# Calculating offsets for sprites on isometric maps?

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

## 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 on other sites
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 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 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 on other sites
Ok thanks I will have a fiddle with the maths!

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011145
• ### Who's Online (See full list)

There are no registered users currently online

×