RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
Ichoris
Pretty, Pretty Fairy Princess


Joined: 20 May 2009
Posts: 6

PostPosted: Tue Jun 09, 2009 3:06 am    Post subject: Algorithm Help [quote]

Many of my sprites graphics have frames that go from a small size to a large size. For example an explosion. Currently every frame is the same size. This is so I don't have to worry about the alignment of the frames.

This is wasting lots of video memory (because even very small frames take up the full amount with lots of trans pixels) so I wrote a trim tool that will find the smallest rect for all images and trim out all the extra white space (trans pixels). Now my images are all optimized sizes which is good.

My question is this:

Does anyone know an automated way to calc the offsets needed to align the sprites. Meaning values I would add/sub before advancing the sprite frame to make them aligned again.
I can't seen to figure a way (with math) that will make this work. It seems like it's should be possible. I use the upper left corner to position my sprites in the world.
It seems like some type of center to largest frame or something could work. Just can't wrap my head around what I need to do.

There is no way I want to line this up by hand.

Any ideas? Thanks in advance!
Back to top  
Ninkazu
Demon Hunter


Joined: 08 Aug 2002
Posts: 945
Location: Location:

PostPosted: Tue Jun 09, 2009 3:41 am    Post subject: [quote]

Let me first ask this: do you load all your sprites from separate bitmaps or are they all packed into large bitmaps? The second is by far the best way to go because of the fewer files one needs to keep track of (better for distribution purposes too). If the sprites inside are irregularly shaped, then an additional markup file should accompany it, specifying which sprites are where by specifying bounding boxes.

For something like an explosion, it all depends on how the animation should look. If it's more of a radial explosion and you wish to lock the middle of the explosion to a target location, the math is pretty simple.

blit the sprite at location (left, top)
targetX - frame[counter].Width/2, targetX - frame[counter].Height/2

If you wish instead for it to be locked from the base of the explosion with the middle on the target location, just take off the /2 on Height above.

If the animation is far more complex with targeting issues, you may want to add offsets to the frame-by-frame animation scripts you write up in order for each frame to be pixel perfect to your liking.
Back to top  
Ichoris
Pretty, Pretty Fairy Princess


Joined: 20 May 2009
Posts: 6

PostPosted: Tue Jun 09, 2009 5:16 am    Post subject: [quote]

I pack all my sprites onto a large texture page. I have a tool (thanks Mattias for the help!) that packs and outputs the width/height and UV/ST data. This allows me to blit a section of the larger sheet where my sprites are and like you said keeps the number of resources down. So I have the bounding boxes already and they don't need to be perfect squares.

I do want to add offsets for each frame. The problem is I don't know how to calc these to make the animations line up. I'm not sure that using the center will work in all cases (I could be wrong).

Some animations are more complex than explosions which is why I think an X/Y offset would be best. I just don't know how to get these values.

Thanks for the reply.
Back to top  
Mattias Gustavsson
Mage


Joined: 10 Nov 2007
Posts: 457
Location: Royal Leamington Spa, UK

PostPosted: Tue Jun 09, 2009 3:05 pm    Post subject: [quote]

In your trimming tool, you find the top-left and bottom-right corner of the non-empty area, right?

If you save out the top-left coordinates for each frame (the distance from the original top-left corner to the top-left corner of your non-empty area from the trimming), that's your offset to use for that frame, to make it positionable in the same way as your non-trimmed version.
_________________
www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
Back to top  
Ichoris
Pretty, Pretty Fairy Princess


Joined: 20 May 2009
Posts: 6

PostPosted: Wed Jun 10, 2009 2:03 am    Post subject: [quote]

I do this exact process when aligning trans from one animation to another. For some reason I didn't think of doing it to solve this problem.

Thanks!
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum