Constant 2D Motion: I Don't Get It
The subject says it all... I finally got D3D8 transforms down (I''m working in 2D, by the way, but I''m NOT using the ID3DXSprite8 interface), so now I can make things move. However, I can only move in certain large increments - like, 100 pixels per keypress or something like that (whatever I have hard-coded at the time). The question here probably has a real simple answer, but...
I figure I can make a MOTION struct(xSpeed, ySpeed, zSpeed) to test translations (since I won''t be doing any rotation/scaling in this project). I figure I can move the sprite by giving it a velocity, then having it''s position changed in my Update() function, then rendered in the Render() function. However, how will I know when the motion is finished?
I.E. Say I want to move a square to the right at 100 pixels in a smooth motion (instead of a sudden jump). What do I do?
-Normie
PS. I know, I know, it''s probably real simple, but hey, I''m a simple person.
PPS. Anywhere I can find a tutorial on threads, using them, and how they relate to games?
I am a devout follower of the
"Lazy Programmer''s Doctrime"(tm)...
and I''m damned proud of it, too!
-----
"I came, I saw, I started making
games." ... If you''ll excuse
me, I must resume my search
for my long lost lobotomy stitches.
There are lots of ways to do this. One way to do it is to store a destination and stop when you get there, or store a starting time and set and ending time and interpolate based on the current time.
For example, I have a bullet moving from 25,25 to 100,100 in one second (1000ms). I store the starting time and compute the vector from source to destination (75,75) (dest-source). Each frame I look at the time elsapsed since the last frame and add (last frame) / (total movement time) * (vector). Suppose there are 100ms between frames. This means I will add 100ms / 1000ms * (75,75) or (7.5, 7.5) to my current position. You can see that I will arrive at (100,100) after 1 second, or 10 frames of animation.
For example, I have a bullet moving from 25,25 to 100,100 in one second (1000ms). I store the starting time and compute the vector from source to destination (75,75) (dest-source). Each frame I look at the time elsapsed since the last frame and add (last frame) / (total movement time) * (vector). Suppose there are 100ms between frames. This means I will add 100ms / 1000ms * (75,75) or (7.5, 7.5) to my current position. You can see that I will arrive at (100,100) after 1 second, or 10 frames of animation.
well, geez, that throws my whole program out of the window.
Oh well
-Normie
I am a devout follower of the
"Lazy Programmer''s Doctrime"(tm)...
and I''m damned proud of it, too!
-----
"I came, I saw, I started making
games." ... If you''ll excuse
me, I must resume my search
for my long lost lobotomy stitches.
Oh well
-Normie
I am a devout follower of the
"Lazy Programmer''s Doctrime"(tm)...
and I''m damned proud of it, too!
-----
"I came, I saw, I started making
games." ... If you''ll excuse
me, I must resume my search
for my long lost lobotomy stitches.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement