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.
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.
About the author
Associate James Ford
Sickhead Games
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.