Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Load sprite sheet?

Author
Message
2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 16th Oct 2012 02:32
I have many sprites and do not want to load each image at a time. Is there a way to load 1 huge sprite sheet and grab the size of each one through a loop?

for j=1 to 100
for i=1 to 500
image=loadImage("sheet.png")
rem what code can i use to extract frame?
next i
next j
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 16th Oct 2012 03:01 Edited at: 16th Oct 2012 03:03
You don't need a loop. Look at the SetSpriteAnimation() command. Or, if they aren't animated, check out loading sub images.

2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 16th Oct 2012 04:21
LoadSubImage ( iImageIndex, iParentIndex, sImageFilename )

I've looked at that command, but I'm still not sure how can you grab a section of an image? Example if my whole image is 100x100 and I only want to grab upper left hand corner 25x25, how can I accomplish this? Are there any examples to look at?
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 16th Oct 2012 04:57
http://forum.thegamecreators.com/?m=forum_view&t=194134&b=41

Have a look in that thread it should explain it.

Auger
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 16th Oct 2012 05:31 Edited at: 16th Oct 2012 05:32
There's also an image joiner tool in your AGK/IDE/Utilities. If you run that (see the help files for how it works) and then look at the output, you'll get an idea how to make a subimages.txt file. Also see my HOTspot Designer for another way to assign different parts of an image to a subimages.txt file.

And there's even ANOTHER way to do what you want, with CopyImage().

2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 16th Oct 2012 19:57
Auger - Thanks for the link. That was really helpful!

Rich Desheimer - The demo is pretty cool. I may use it for one of my future game.

I've wished they add clear examples for loadSubImage in the document. It would save me and other people a lot of times.

LoadSubImage ( iImageIndex, iParentIndex, sImageFilename )


Thanks everyone for answering my questions!
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 16th Oct 2012 20:21
Here you go: I use multi .agc files but you don't have to.

Main.agc:



walls2_subimage.agc:



code for displaying the image:



Here is the .txt file that defines the images. Note the name of this file is the same name as the .png file in the first file it is walls2.png so this file must be called walls2 subimages.txt or walls2_subimages.txt (if you are going to use FE)



Hope this helps

Login to post a reply

Server time is: 2024-11-23 23:33:38
Your offset time is: 2024-11-23 23:33:38