Jump to content
  • Advertisement

Archived

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

VermiciousKnid

Motion of Sprite

This topic is 6174 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, 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 (yposition<goherey){
yposition++;
} else if (yposition>goherey) {
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • 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!