Still having trouble with 90-degree turns...

I’ve managed to do a 180 degree flip using drawImage() but I can’t seem to get 90 degrees. If I draw a single Pacman with his mouth pointing, say left, can’t I use drawImage() to render that image with him pointing up, down, and right? Given that the sprite is 32x32:

drawImage(img, 0, 0, 32, 32, 32, 32, 0, 0, null) should turn a left-facing Pacman to a right-facing Pacman. I can’t figure out how to get an up/down facing Pacman, or is this not possible and the image is only flipped?

Michael Bishop

It’s not possible…
The drawImage() methods allow you to translate and scale the image (even do a bit of clipping with the xs1,ys1,xs2,ys2,xd1,yd1,xd2,yd2 version) but there is not rotation included…

You will need a second set of sprites for the vertical animation.

Rafael

Oh, I think the other topic on mirroring an image confused me. I was under the impression you could get 90-degree rotation, but I guess it’s only 180. Still, two sets of sprites is better than four!

Thanks.

Michael Bishop

Bishop,

I am really sorry, since I guess I was the one who confused you with the mirroring thing.

I thought, back in the other thread, that you wanted to simply rotate left/right and up/down. Now I realise that what you want is a tad different, and more difficult.

Sorry for the misunderstanding…