Sign in to follow this  
kingpinzs

is there a better faster way to move image on screen(c++, windows)

Recommended Posts

this is what I have lpBackBuffer->BltFast(x, y, g_pddbug, &r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); else if(wParam==VK_DOWN) //check for down arrow key { if(y != 800) { y++; } return(0);//handled message } //************************* else if(wParam==VK_UP) //check for up arrow key { if(y != 0) { y--; } return(0);//handled message } //******************* else if(wParam==VK_LEFT) //check for left arrow key { if(x != 0) { x--; } return(0);//handled message } //************** else if(wParam==VK_RIGHT) //check for right arrow key { if (x != 600) { x++; } return(0);//handled message } But it takes forever to get from one side of the screen to another. is there a faster better way to do this with out using direct input

Share this post


Link to post
Share on other sites
Instead of using the operator ++ , couldn't you use += # ? Add more than just one each frame, and it should still look smooth, but move more quickly. Try something like 4 or 8 pixels a frame. Choose whatever suits you the most.

Share this post


Link to post
Share on other sites
It looks like you're moving your image 1 pixel at a time.

You have to remember, even if you're running at 60 FPS, it'll take you 10 full seconds to move all 600 pixels across the scene.

What's your FPS? Because if you want to increase the speed of your movement, and you have a decent framerate (at least 30), then the only thing you can do is change how many pixels your images move every time you tell it to move. Increasing input speed with DirectInput isn't going to help you.

Try changing your values by 2 or 3, not just 1, and see if that gets what you want.

Remember, lots of movement in games is more than 1 pixel at a time.

Share this post


Link to post
Share on other sites
thanks that works great. Using the same example how to I change it so I can animate the movement.

r.left = 0;
r.top = 0;
r.right = 64;
r.bottom = 64;
lpBackBuffer->BltFast(x, y, g_pddbug, &r,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);

how do a change it when I press a key it changes the image and will loop so it looks Like mt image is moving?

I know it has something to do with changing r.right and r.bottom

but I need it to loop for each key stroke

thanks for the help

Share this post


Link to post
Share on other sites
Does your single image actually contain multiple frames of animation? Or is it just a simple 64x64 image?

Typically, animated sprites like this will be saved as really wide images. If it has, say, 8 frames of animation, and each frame is 64x64, then the actual image will be 512 pixels wide (but still 64 high).
+---+---+---+---+---+---+---+---+
| | | | | | | | |
+---+---+---+---+---+---+---+---+

To draw a different frame onto the back buffer, you would need to change the .left and .right values of your source rectangle. The first frame will have left/right values of 0/64, just like in your example code. The second frame will be shifted over 64 pixels, so your left/right values will be 64/128. Your top/bottom values remain the same. All this rectangle does is say which section of the overall image you want to copy from.

You'll have to store another value elsewhere so that you can remember which frame you are on, and increment the frame number each time you get a new keypress.

Share this post


Link to post
Share on other sites
my image is 64 tall 195 long with 4 differnt images.

So when I push up I want it to cycle through those images.

that is what I was thinking.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this