Skip to main content
gamedev.net
🔒 Locked

Locations

Started by nex7 12 replies 1.5k views
Original Post
nex7
nex7
I am starting on the animation for my game and was looking at the current way i do locations. Right now my locations are array indexes....so pretty much tile indexes. I think i should be using world coordinates instead. Do you use world coords for everything including items like trees? I know i need something to make the transition from tile to tile more smooth when the mob is moving around. I will probably store them in the correct tile position but the actual location will be in the larger world coords. am i on the right track here?
streamer
streamer
I'm using array indexes for everything + world coordinates for sprites.
nex7
nex7
Here is a screenshot of the editor. It is a little rough around the edges atm but im working on it. Sorry for the art...i dont have an artist and i dont have the time to do it myself so i went with an easier idea. The basic concept is that all of the world is drawn in some kids notebook hence the college ruled paper look.
Screenshot
nex7
nex7
so your sprites use world coords then?...or everything uses indexes and your sprites use world coords as well?
streamer
streamer
You meen


Screenshot

I see you have nice big monitor :)
But don't put large pictures in post, just put link

PS: for link you use / and not \\
nex7
nex7
sorry bout the huge image..i made it a link now.
streamer
streamer
Quote:
Original post by nex7
so your sprites use world coords then?...or everything uses indexes and your sprites use world coords as well?


everything uses indexes, and sprites use world cords as well because my routine for calculating distances from enemies, and collision between enemies and players need these coordinates.
I use indexes just for drawing.
nex7
nex7
hrm...i kinda figured world coords would be better for drawing. If i make the objects move from one tile to the next they will jump instead of move smoothly.
streamer
streamer
If your object moves then actually it's sprite so threat it like a sprite. :)
nex7
nex7
Im sorry ...object = sprite...

so what im hearing you say is that you use Worldcoords for sprite movements and when the movement is finished it ends up at a tile coord all of the time?
streamer
streamer
Something like that, but both of coordiantes are updated constantly. Tile coordinate is used mostly because program need to know which tile has something on it and do a enemy or player can pass over it, or not.
World coordintes I use just for drawing, collision and determining distance between two entities on map.
kvp
kvp
Did anybody notice that world_coordinate = tile_coordinate * tile_size ?
When you store world coordinates for an object (sprite), you can always get it's current tile position by dividing it with the tile size.
streamer
streamer
Quote:
Original post by kvp
Did anybody notice that world_coordinate = tile_coordinate * tile_size ?
When you store world coordinates for an object (sprite), you can always get it's current tile position by dividing it with the tile size.


It's true.

Imagine this: You have world with size of 100.000 size by x and y axis. First normaly thought about this, I need to split map and load it separatly. So you split your map into small pieces and load them dynamicly in game. Let say you splited your map into small maps of size 1000x1000. That means that you have 100*100=10.000 small maps. Now when you use tile coordinates, you use them localy. They should be in range from 0 to 100. And now having world coordinates make sense. But also it make sense having tile coordinates too.
World coordinates to know when you need to load new map piece (when too close to border of current map, when calculating distance to nearest town etc etc).
Tile coordinates for intersections checking, drawing, AI movement etc.


nex7
nex7
when I say world coords I am mainly talking about screen position. so my world coords are something like

public Point WorldToScreen(int x, int y)
{
Point p = new Point();

int offsetOdd = ((y) & 1) * (TileWidth / 2);

p.X = (x * TileWidth + offsetOdd)-(ScreenOffsetX * TileWidth);
p.Y = (y * (TileHeight / 2))-(ScreenOffsetY * (TileHeight/2));

return p;

}

So when i get down to movement i am talking about moving something from one point to another and knowing where to draw it along the way over a period of time.

x and y are array positions in a 2d array...each array is a layer and i have 4 layers.

only 1 layer will be able to move.

i can take any screen position and tell which tile its on so knowing which tile my sprite is on at any given time is no problem. But somewhere im going to have to store each sprites current screen position for rendering the movement sequence.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.