#### Archived

This topic is now archived and is closed to further replies.

# Motion of Sprite

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

## Recommended Posts

Hey, Is there an easy way or a DirectX function to move a sprite from a certain point x1,y1 to x2,y2 without using trig functions or square roots after every frame? Not like a warp from one place to another, but a discrete walk. Like in Diablo where you click a point and the character walks in a straight line. What is the most effecient way to accomplish this? VK

##### Share on other sites
there may be a more clever way but what I'd do is:

if (the current y position is < the destination y position) current y position=current y position+1;
else y--;

then the same for the x position;

there's probably nicer ways though...

A CRPG in development...

Need help? Well, go FAQ yourself.

Edited by - Nazrix on September 25, 2001 9:20:56 PM

##### Share on other sites
I believe that particular code would make the player slowly move upward, as a result of the else y--;, because whenever the specified spot is equal to the player''s location, it would run the else part... i think... i may be wrong...

heres what i''d do:

  if (ypositiongoherey) { yposition--;}

and then again for the X coords...

But yeah, its a good idea, whenever the mouse button is pressed, and it is within the boundaries of the screen, then the "goherey" and "goherex" are set to wherever the mouse was at the time of the click. You would probably run into problems when trying to navigate barriers though, and i dont even want to think about how that would be done...

hope it helped...

__
Tsu

##### Share on other sites
quote:
Original post by Tsu
I believe that particular code would make the player slowly move upward, as a result of the else y--;, because whenever the specified spot is equal to the player's location, it would run the else part... i think... i may be wrong...

heres what i'd do:

Actually, you're right about that...I was just writing quick pseudocode and not really thinking it through completely

A CRPG in development...

Need help? Well, go FAQ yourself.

Edited by - Nazrix on September 25, 2001 9:42:18 PM

##### Share on other sites
Hi,
It looks you are developing an Iso Engine. Maybe this can help.
While developing KEngine, I reached the same problem. And is one of the bigger problems I must say.

At a first look, it seems that the right way is to do it is to use screen coordinates, but finally I decided to drop everything and build an internal continual spacemap. More like 3D programming.

Let me explain.
You separate your game in three parts:
A. The resouce manager. This part has the memory managing tasks. If you need a graphic or sound then this is your man.

B. The Scene. Think about it not aas the image you draw, but as a simulation. Do you remember those physics problems on school? You have a 2D or 3D space where particle objects move, each one with its own speed, direction, position, etc. All in floating points. This is your map, a continual space. Just make your objects walk, run, or anything here. Remember, it is just a simulation. It is what you should call ''Engine''.

C. The renderer. Yes, the renderer is apart. Think about it as a camera. You have your scene above with objects moving. This class has the job of capturing a portion of the scene and presenting it as you need. The simulation can keep running, the renderer shows what is happening. It transforms coordinates and shows. The beauty of this is that you can change your Renderer object to adjust to 2D or 3D or any viewing point you wish and the engine will keep running.

And dont worry about sqrts and speed, the greatest bottleneck here is the blitting speed and light processing.

Good luck
Guimo

P.D. I have some screenshots on the Showcase. use the following link:

http://www.gamedev.net/community/gds/projects/default.asp?projectID=298

1. 1
Rutin
39
2. 2
3. 3
4. 4
5. 5

• 12
• 17
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633358
• Total Posts
3011506
• ### Who's Online (See full list)

There are no registered users currently online

×