Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Moving a Sprite without user input

Author
Message
jjeff
13
Years of Service
User Offline
Joined: 11th Mar 2011
Location:
Posted: 31st Mar 2011 00:12
Hi, I am trying to move a sprite across the screen when a particular function is called. i want to see the sprite move across the screen. I would think that this would be done by moving the sprite one pixel and then pausing for a given amount of seconds before moving the sprite another pixel. However, i wrote my own pause function and all my program does is pause for a long time and then creates the sprite rather than moving it one pixel, pausing, and repeating.

my pause function:


my call to the pause function:
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 31st Mar 2011 04:49 Edited at: 31st Mar 2011 04:50
You would more want to do it on a timer based system, like:

int timer=0;
bool settimer=false;
int spritemovements=0;
bool movesprite=true;

if(spritemovements==10)
{
settimer=true;
movesprite=false;

}
if(settimer)
{
timer++;
}

if(timer>9)
{
timer=0;
settimer=false;
movesprite=true;
spritemovements=0;

}

if(movesprite==true)
{

//code to move the sprite here
spritemovements++;
}


Thats just an example, but you get the idea, you want the movement code to be dependant on if the timer is ticking or not, once the timer stops ticking, then move the sprite. Then count how many times you move the sprite, and once it reaches the desired amount of times, stop the sprite and start the timer again.

Here's a working program to demonstrate:




Login to post a reply

Server time is: 2024-06-16 03:03:35
Your offset time is: 2024-06-16 03:03:35