Hi Jack,
The problem is that an SDL::Rect stores it's x and y coordinates as
integers. When you subtract a small value from the coordinate the new
coordinate is truncated, which is why you are able to move in negative
directions. When you add a small value the same thing happens, but the
truncated value is the same as the value you added to, so no movement. To
work around this, store the coordinates in variables outside of the rect,
add and subtract using these variables, then update the SDL::Rect
coordinates.
Jeff
On Sun, Jun 10, 2012 at 7:50 AM, Jack Maney jma...@adknowledge.com wrote:
Everyone,
First of all, thanks to Tobias Leech for so quickly answering my previous
question on alpha values.
Now, I'm trying to understand movement. I managed to hack together a
simple, choppy, movement by teleportation app in which one can use ASDW
to move a rectangle around in the screen. However, inspired by the Pong
code in the SDL manual, I'm trying to recreate this properly by using
motion handlers. The resulting code is at http://pastebin.com/mVHANk7T
The strange thing about it is that movement works just fine, but only up
and to the left (ie via A and W) not to the right or down (ie via D and S).
I'm at a bit of a loss as to what's going on...why would a negative
x-velocity and positive y-velocity be fine, but not a positive x-velocity
or a negative y-velocity? I know that the correct velocity values are
being set (by de-commenting the debugging print statement and running the
code), so it's not an issue of the wrong velocity values being set... Is
there something obvious that I'm missing here?
Thank you for your time,
Jack
--
Jeffrey T. Palmer