Jump to content
  • Advertisement
Sign in to follow this  
CelticSir

Calculating offsets for sprites on isometric maps?

This topic is 2346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey

I was wondering how computer games make sure that images are placed with a correct offset on their maps.

My script draws the sprites in their correct location, but naturally a sprite image might vary in size.

Is there some way to calculate how much offset is required in order for it to load on the tile correctly, or do game devs usually manually edit the offset until it "fits" then store it?

Share this post


Link to post
Share on other sites
Advertisement
You could either make every sprite image the same size and hard code the offsets (easy way) or you could do on-the-fly calculations for the offsets (hard way). In the latter case, you create a standard point of reference for the sprites (e.g., center of the sprite image).

Share this post


Link to post
Share on other sites
Well this is what i have as the issue at hand:

http://imgur.com/2kZEF

The one building fits fine this is with a simple formula as its same size i simply add Y axis by image half.

How ever the secondary (larger building) is completely wrong. Ideally i want calculate what their offset should be then store it so i don't have to do it on the fly, but itll save me alot of fiddling. (so kinda bit of both of what you said).

But i don't know how to work out the calculation to make them fit.

Share this post


Link to post
Share on other sites
There is no simple formula, because no formula can "know" how you have been placing your pixels. You would still have to rely on at least some basic rules for your artists, like making sure that there are no transparent lines below the actual sprite and that the sprites are always perfectly centered.

If you can't control your art, I'd probably go through the actual image data, find the lowest line with opaque pixels, pray that the center of those aligns with the lower tip of a tile and base the offset on that.

Based on the visible part it would also seem that the sprite is covering more than a single tile. If a sprite is extending over multiple tiles in a non-symmetrical way (for example also covering the tile at x-1,y) the above approach would still work, BUT only if the sprite is assigned to the lowest tile.

To simply align the lower edge is just a matter of y_offset = tile_height - image_height, assuming your y-axis is downward and for drawing you specify the top left corner of the image. If your images are at least all centered x_offset = (tile_width - image_width) / 2.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!