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 / Yet another Atlas/LoadSubImage + texturepacker Question

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 14th Apr 2013 20:00
Hi
After Searching I found a lot of questions about loadSubimage and atlases but I really could not find a simple setup example of how to use an already existing atlas textur and make a animated sprite.

I've made my atlas and sheet in texturepacker. And it creates two files - a "Climb.Png" and "Climb.txt" file

Could someone please explain in code how I set up a sprite with animation using these two files?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Apr 2013 20:50
first you set the rectangle of the sprite
i use a atlas texture with 128x128 pixel sub images
the last number is the picture count.
SetSpriteAnimation( spr, 128, 128, 13 )

you can play them all up or down
30 fps loop 1-13
PlaySprite( spr, 30, 1, 1, 13 )
30 fps loop 13-1
PlaySprite( spr, 30, 1, 13, 1 )

or you can animate self by set the frame you need
GetSpriteCurrentFrame
SetSpriteFrame

the texturepacker don't sort my images, i wrote
some rows of blitzmax code to put some images together.
in agk its possible too.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 14th Apr 2013 21:21 Edited at: 14th Apr 2013 21:23
Hi Markus, Thanks, But..

I already know how to setup an animation with setSpriteAnimation and an image sheet with sprites in the same size.

What I'm wondering is how to use an atlas or "subimages.txt" file to make an animation.

SetSpriteAnimation is great and all but you need a sheet with sprites in the same size and in correct order(sort of).

And it means I can not use subimages with different sizes.
Texturepacker can make atlases that have just that.

As I understand it, a "subimages.txt" file does not need a sheet with sprites in the same size - that's the whole point of LoadSubimage and atlases - isn't it?
Auger
12
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 14th Apr 2013 23:06 Edited at: 14th Apr 2013 23:11
I'm not sure how texturepacker writes it's file so you might have to edit it a bit. In AppGameKit the subimages files are written like this

Quote: "
back1.png:0:0:256:128
go.png:768:0:128:128
back.png:896:0:128:128
"


You have the name of the file to load then the top left 2 (x,y) coordinates and then the bottom right (x,y) ones of your sub image.

then rename the file xxxxx subimages.txt so for the climb example you'd have to rename the file climb subimages.txt

Then to use that given your Climb.png example here is the code you would need

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Apr 2013 23:16
Not really reading your question eh

My hovercraft is full of eels
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 14th Apr 2013 23:41
Thanks Auger

I understand now that loadSubImage together with texturepacker is a lot more work than I thought. It seems I have to name all the files I use in texturepacker to a number for it to be reusable in a function. Or I have to create a new exporter for texturepacker that renames the files I use with numbers.

The lesson is, as usual: "no free lunch"

Damn, I never learn.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Apr 2013 23:42 Edited at: 15th Apr 2013 13:27
edit:
LoadSubImage use a part of atlas image.
you can build your animation with this

SetSpriteImage(spr,img[1])
ClearSpriteAnimationFrames( spr )
AddSpriteAnimationFrame( spr, img[2])
AddSpriteAnimationFrame( spr, img[3])
AddSpriteAnimationFrame( spr, img[4])
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 14th Apr 2013 23:49 Edited at: 14th Apr 2013 23:52
Quote: " you don't need a atlas texture if you have the original images"


Well, the reason you should use atlases/sheets is to pack sprites to save memory. A 400x400 sized image use the same space as a 512+512 image.

So, Yes, packing all my images into sheets saves a lot of memory and, as I understand, is also faster if you have a lot of assets - in the end.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Apr 2013 23:51 Edited at: 14th Apr 2013 23:51
i use images for sprites in the size 32 64 128 256 512 ... is the same
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 14th Apr 2013 23:55
Quote: "i use images for sprites in the size 32 64 128 256 512 ... is the same"


But I don't. I use Sprites that are 100x140 or other dimensions that is not in the power of 2.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Apr 2013 23:57 Edited at: 15th Apr 2013 14:01
with getsubimage it will be resized to 128x256 i think, because
the texture must be power of 2.
where is the save of memory?
edit:getsubimage use part of the altas image direct.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 00:00 Edited at: 15th Apr 2013 00:10
Quote: "with getsubimage it will be resized to 128x256 i think."


What?
I really need a confirmation on this.

EDIT: The whole point of making atlases is to save memory isn't it? You store a large sheet of sprites in different sizes. The program uses this atlas as a reference to draw the sprites.
CreateSprite does not create another image - it creates a reference to an image.

EDIT: or rather, as the whole point of atlases, it creates a reference to a selection of an image.

Somebody have to correct me if I'm wrong here.
Auger
12
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 15th Apr 2013 00:08 Edited at: 15th Apr 2013 00:09
Do you have all the sprite images separate or are you trying to use an existing sprite sheet? if you have them all separate you can use the IMAGE JOINER. It's in AGK>IDE>UTILTIES folder. With it you just dump all the sprites into a folder , run the image joiner tell it the final max size of image and it'll pack it all together for you and make the subimages.txt file.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 00:14
But this is what I use Texturepacker for. Wich is a much better program...and has a lot more features.

I'm not asking how to make a spritesheet here....
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Apr 2013 00:20 Edited at: 15th Apr 2013 00:21
if createsprite need a power of 2 texture and use the image as reference it must be resized.
the getimagewidth told me the original size, this confused me.
at my board game i used images with the wrong size (not power of2, a little bit over),
i make them power of 2 and it was faster, that's my impression.
at direct x is one surface faster then more surfaces, there
atlas makes sense. if opengl faster too with less surfaces i don't know.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 00:28 Edited at: 15th Apr 2013 00:28
Markus, this topic has really got me wondering about the reason behind the implemation of "loadsubimage" and atlases in the first place.

Atlases is for packing images isn't it? So what the heck do you accomplish if LoadSubImage creates another image in memory?

This is really strange.

I really wonder why LoadSubimage exists in the first place.

And does CreateSprite need a power of 2 image?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Apr 2013 01:40
because you want use images with different sizes.
with SetSpriteAnimation you can use only one size.
by the name LoadSubImage create a new image in memory.
if not, if you delete the atlas image from memory
it must stay in memory until you delete both.
maybe LoadSubImage make a virtual image and use your atlas image, i don't know 100%.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 02:07
I don't know either. Guess we have to wait for some developers to help us with this...

Thank you for your dedication to my post, Markus!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Apr 2013 02:36 Edited at: 15th Apr 2013 02:37
ok, some deeper information should be part of the manual.
@Paul
my question is, use LoadSubimage the same parent image memory?
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 15th Apr 2013 09:55
Subimages don't need extra memory they use the memory from the atlas texture.

If you want to know what subimages are in an atlas texture, you can read the contents of the subimages file with opentoRead() and parse the list - pulling the filenames into an array. Then use this array to load the subimages.

It does save memory with odd sized frames.

subimages do NOT need to be a power of 2 and they wont be adjusted up to one.

Only actual file loading benefits from power of 2 images - load subimage is not a file load, it uses pointers to the atlas texture.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Apr 2013 12:03
Marl is correct. The sub image is just using a pointer to the main image and uses no extra memory.


this.mess = abs(sin(times#))
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 13:17
Quote: " The sub image is just using a pointer to the main image and uses no extra memory."


This is what I thought.

Using an Array on the file is of course a splendid idea.

Thanks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Apr 2013 13:32
@Marl & baxslash,
ok thanks.

@Timshark
i don't said anything
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 14:14
Quote: "i don't said anything "


Oh yes you did

You said that the whole world should be in the power of 2.
- and sometimes I really wish that was true.

thank you for the semantic exercise - it was great

Login to post a reply

Server time is: 2024-05-04 18:08:32
Your offset time is: 2024-05-04 18:08:32