Jump to content
  • Advertisement


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


handling movement of objects

This topic is 5707 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

I have a GameManager class that contains all objects in the game, including input/sound/rendering class. Now, GameManager has a function called Present() that basically renders all objects, play sounds etc. It works like this: d3ddevice->BeginScene() // for each object object->render( ... ); d3ddevice->EndScene() Now, I got stuck with the process of movement. If I have an object, let's say, A, and I want that object to move from (0,0) to (5,5), obviously I can't use a loop, that way all other objects will be "halted" until A reaches (5,5), so the movement must be handled on the per frame basis. For each frame, for example, move A .2 to the right, and .2 downward, so in 25 frames, A will reach (5,5) -- this is just an example. But I am not really sure how to do this. How do I make in such a way that the rendering process of A doesn't know to where A is moving. I don't want to have something like X += .2 in the render() function of A. render() function should only render A based on where A is. The movement must be handled somewhere else, meaning, I have to create another function called move() and I *have* to call this function to update the X and Y position before the rendering process. Now, surely, I don't want GameManager to do this. I don't want GameManager to instruct A to move to a specific location, A must be able to handle itself, A must be able to update its location at each frame drawn....but how??
Current project: A puzzle game.
% completed: ~0%
Status: Active.
[edited by - alnite on May 1, 2003 2:03:08 PM]

Share this post

Link to post
Share on other sites
well make an update function then

if u want obj A to move by itself then give A a destination vector. then for each frame do

a.vPos = a.vPos + (a.vDest - a.vPos) * a.Speed * frameInterval
(a.Speed is a float here from 0 - 1, if u wanna use units then
use Normalize(a.VDest - a.vPos) * a.Speed)

(so at 30 fps or 500 fps ur object moves at the same speed)

if u wanna pause the game then

if (!sysPaused) UpdateEverythin();

[edited by - Ilici on May 1, 2003 3:16:58 PM]

Share this post

Link to post
Share on other sites
Make Update(fElapsedTime) function for GameManager. Update all the objects'' positions (speeds, accelerations, etc.) in the Update function. For each object, use a flag to express "this thing is moving", and define a destination point.

I hope it helps.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!