Advertisement

Moving sprites

Started by July 09, 2000 12:21 PM
3 comments, last by Zombie 24 years, 5 months ago
I''ve asked this a long time ago before... now gotta ask again Well I''m doing this map editor, which is tile-based. It currently has 3 layers, and that third is for all characters (or anything that moves, like bullets, missiles, ships etc etc). Now I really don''t know how to move those npc''s. Of course, when I press the key, it (the object) moves, but it moves only in screen coordinates, when it''s supposed to move in world (map) coords. My map struct is following- map(layer,x,y) [where x and y are obviously tile numbers, beginning from 0] My rendering loop is basically the same than in Bracket''s example, I simply changed it to tile-based (so that I''d understand it better) I''m sure this''s a simple thing, I just don''t get it..
Well, you''re saying that these objects are using screen coordinates and not the world coordinates. You must be using a variable or two to keep track of which tiles you are drawing according to where the main character is in the world. Suppose the variables xworld_camera and yworld_camera are supposed to be set for the left hand corner of the screen. To get the world coordinates of your objects, you would do:

xworld_camera + xscreen_coords (of the object) = xworld_coords;
yworld_camera + yscreen_coords (of the object) = yworld_coords;

Hope that clarified the situation a little.

Any more problems, post ''em.

Martin


______________Martin EstevaolpSoftware
Advertisement
quote: Any more problems, post ''em.
Sure thing

Sorry.. I wasn''t clear enough. I''ve got those coordinates, they are stored in vLT (LeftTop). vLT.x and vLT.y.
Full map struct is this:
Public Type tMap offset As intPoint dxo As zDXObject3D zIsEmpty As Integer   '' tilesize As intPoint  ''End TypePublic Type intPoint x As Integer y As IntegerEnd TypePublic Type zDXObject3D ''txtr As DirectDrawSurface7 texture As Integer '' my textures are stored in array of surfaces, this is the index of array vertex(3) As D3DTLVERTEX srect As D3DRECT wdh As Integer  hgt As Integer end Type 




When I press a key, left button for instance, map(3,1,1).offset.x =map(3,1,1).offset.x -1, so the object appears to be slightly more to left than before (that''s obvious ). But I don''t know how to do this in world coords: when I scroll the map, no matter where the object looks to be, its location is read from map array (1,1). I don''t know how to change this- and even if I could move the entry in array, there would be another problem- what if I want more than just 1 object in the same location? That wouldn''t be possible with that solution.

So please, someone help, help, help!
First you have to figure out if the object is on screen. If it is on screen, you convert its world coordinates to pixel coordinates. Then you draw the image at that location. If you store everything in world coordinates, then convert them to pixel coordinates only when drawing, you should lessen your problems. Hope that helps

- Daniel
- DanielMy homepage
The sprite most likely is tied to some class (or struct) that describes an object. In this class, you need 3 variables:
1) (private) tMap *mMapPt;
2) (public) unsigned char OffsetX, OffsetY;

Here''s what they are used for. mMapPt is a pointer to you map array. It''s only here for when you want to look up where (what map point) the object is over. OffsetX and OffsetY are the actual pixel offsets the map object is over that map point. When you move an object, call a function Move(unsigned int X, unsigned int Y) that alters mMapPt, OffsetX, and OffsetY. For instance:

Assume that an NPC is standing over a tile at the very center of that tile. Given that the tile is 64 by 31, the object is standing at the offset of (32, 15) on that tile. Now when you move to the left, you would call cMapObj->Move(-1, 0). This function will change the offset values for this object (now 31, 15). When it comes time to paint the map object, you find the screen coordinate of the tile that it''s on, add the offsets, and draw.

I hope this helps you. I hope that I read the problem right. God... I hope I just didn''t write all of this for nothing.



Dino M. Gambone

Good judgement is gained through experience. Experience, however, is gained through bad judgement.

Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.

Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/

This topic is closed to new replies.

Advertisement