Question

See Having Some Issues With Making Pacman to understand this question fully. Just look at the first part of the accepted answer. And this is in java!

I am using the array as shown in the link above. I have my pacman character moving around fine other then the fact that it is moving 21 pixels every 100ms therefore it's not smooth at all.

Currently I'm just multiplying the x and y of the current array position by 21. I'm wondering how I would go about making this smooth. I have tried some ways of how to move but they have not worked and I'm not very skilled and my ways are not efficient, therefore I have come here looking for a good way to move around smoothly.

Some things that you may need to know: Pacman is first checking spot in direction of key press.(example: right arrow down. Is it clear?) If clear it will proceed to call another class which handles moving pacman until there is a wall or enemy.

Was it helpful?

Solution

You need to create two loops. A game loop, which works out the logic of the game, and runs every 100ms, and an animation loop, which runs more frequently, maybe every 20ms and calculates where all the sprites should be.

// in pseudo code
sleep 20 ms
if i++ % 5 == 0
    do game loop
do animation loop with i
// passing i to animation loop will allow you to easily calculate how far sprite is along path to destination

OTHER TIPS

The human eye can see about one frame every 100ms, with some people being able to see faster than that. You may wish to increase the frame rate to at least 20FPS (which is equivalent to one frame every 50ms). If you wish to keep Pac-Man moving at the same speed, you can half the distance and double the speed (make him move 10 or 11 pixels every 50ms).

See The Wikipedia article on framerate for more some basic background information, and to see what others are using successfully.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top