Game Development Community

Moderately complicated question about rotation/sprites in TGB

by Josias Gibbs · in Torque Game Engine · 08/17/2008 (10:41 am) · 3 replies

The Issue:
Ok, I have a spaceShip.png file with 72 cells in it. The first cell (in the upper left corner of my image) has a picture of the spaceship facing directly to the right. The second cell has it rotated 5 degrees counterclockwise (ie: facing right and slightly up) The third cell has it rotated 5 MORE degrees counterclockwise (10 degrees total). By the 72 cell (in the lower right corner of my image), the ship is rotated a total of 355 degrees, thus completing the circle.

What I want to do in TGB: When the player presses the left arrow key, I want their ship rotate to the left (and right rotates right, and up thrusts forward). Also, I want the correct cell of the spaceShip.png (the player's ship sprite) to show on screen (something like: frame = (player.rotation)/5)

At first glance this sounded simple, but my issue is that TGB seems to rotate the ship sprite automatically as soon as I change the rotation variable - which makes it so that when I change the frame of the sprite, it ends up rotated twice as far as it should be.


The Solution:
I think this could be solved if I could change the rotation variable (or some similar variable) of the player's ship without the sprite getting automatically rotated. That way, I could display the correct subframe of the sprite myself, and still use that rotation variable (or something similar) to thrust the ship in the direction that it's facing. But... I'm not sure how to do this :(


I know that this is a rather LONG question - so any help would be doubly appreciated.

#1
08/17/2008 (12:48 pm)
Is your game an isometric persp or something, is that why you have a turning animation?

You could try having a regular t2dsceneobject to represent your objects rotation and velocity with a t2danimatedsprite mounted to it (without track rotation) to represent it visually.

To move the object you use setlinearvelocity or whatnot on the sceneObject, to have it appear rotated you set the animation frame on the animatedSprite.
#2
08/18/2008 (10:17 am)
Oo - that sounds like it would work. I'll try it out.

edit: the game's not quite isometric, it's more like half way between isometric and top-down - but yes, that is why I need an animated sprite.
#3
08/19/2008 (5:25 pm)
Thanks James - it worked like a charm.