hey everyone,
just wanted to say thanks for all the help thus far (3 threads in probably 2 days )
I have another issue though: So I figured out how to animate my Player on the screen. He seems to be moving just fine until he gets to the point where the screen itself moves with the camera integers. At this point, the animation starts "jumping"; I'm not really sure how to explain it but it stops becoming smooth at the point. Unfortunately I have no video-capture tools on my computer otherwise I'd gladly post an idea of what is going on. If it helps though, here's the code for the drawPlayer function and the rendering if-loop
I know the code inside the if-loops are extremely poor right now because I was just experimenting to figure out what went wrong.
Thanks again
]]>There's no such thing as an if-loop That can't be the code you use
Back-up the source file in question (if you don't already have done so) and start removing ALL code, except what is necessary to test what is going wrong.
Sorry, typo haha.
Good tip! I just found out the problem; its here:
The problem is the the if-statement that checks the ++frameCount with frameDelay. I used this to control the speed of the animation; unfortunately it causes the strange stutter between camera and animation. When I remove it, everything works smoothly but then the animation moves too quickly. Do you maybe have a better algorithm I can use for animation speed? Because my current one causes too much of a stutter; not too sure why
]]>I didn't understand your code. But now that you mention there's an error there, it all makes sense
You need to run along the code in your head to see what it is supposed to do, and then look at your source to see what it is actually doing...
Try separating your player's movement from its animation. Maybe something like:
if (right) { if(++player.frameCount >= player.frameDelay) { player.curFrame++; player.frameCount = 0; } player.x += 5.0 / player.frameDelay; }
]]>
camerax = player.x - WIDTH/2;
...should you be setting this after working out the player.x?
]]>Wow I'm a moron. Thanks for the tips guys. I ended up separating the movement and animation, and then re-valuing the camerax AFTER the movement...now its working pretty smoothly
]]>