// Earlier in program, declare variables
int x = 0; // Declare variables, they should start at 0 or something, not left blank.
int y = 0;
// Later in program, Update function
if ( x == 0 && y == 0 ) // If position is 0,0 then set position to 100,100
{
x = 100;
y = 100;
}
if ( x == 100 && y == 100 ) // If position is 100,100 then set position to 0,0
{
x = 0;
y = 0;
}
// Render surface
apply_surface( x, y , dot, screen );
This might be better, handle key inputs and update dot position based on what keys are pressed.
//Somewhere earlier on
int x = 0; // Declare variables, they should start at 0 or something, not left blank.
int y = 0;
// Handle Input (Pseudo code)
GetInput(); // Get input
if ( PlayerPressesUp == true ) // Decide how input effects dot position
{
y = y + 100;
}
if ( PlayerPressesDown == true )
{
y = y - 100;
}
// Render surface
apply_surface( x, y, dot, screen );
i get the dot to move and all, but when the dots position is 0,0 i want the dot to jump to 100, 100. and the way i had it, it would just create a new instance of the dot at position 100,100. sorry if my first post was not clear on that.
Are you clearing the background every time you draw? Otherwise the new dot will just be written straight to the screen, and the old one will remain, unil it's overwritten.
Ryan Pridgeon C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal Music | Blog
No. Freeing the surface would delete the image data for the dot. That would not solve anything.
To clear the screen, you can either apply a background image, or draw a large black rectangle (using SDL_FillRect())
I also suggest you learn more of the C++ language and practise more programming before you attempt any more SDL... I don't mean to be offensive. Sorry if I am. But I made your mistake and it wasted a good month or so. Learn the language first.
Ryan Pridgeon C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal Music | Blog
RyanPridgeon wrote:No. Freeing the surface would delete the image data for the dot. That would not solve anything.
To clear the screen, you can either apply a background image, or draw a large black rectangle (using SDL_FillRect())
I also suggest you learn more of the C++ language and practise more programming before you attempt any more SDL... I don't mean to be offensive. Sorry if I am. But I made your mistake and it wasted a good month or so. Learn the language first.
exactly the same with me,watch the first minute and a half or so of gyro vorbis' getting started part 2 video ( http://www.youtube.com/watch?v=OaxckMNq0eU ) to see what you should already know.
Maybe I don't quite understand your problem, but why are you drawing it at x+100 and y+100? Don't you want to MOVE the dot to 100,100, not just draw it there?