Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Need help rotating sprites

Author
Message
Robs
16
Years of Service
User Offline
Joined: 6th Jan 2008
Location: plano tx
Posted: 6th Jan 2008 23:34
Hey all,

I'm pretty new to the GDK, and I'm trying to make my player ship sprite rotate (trying to do an asteroids type game). I have a player update loop which I'm calling from the main update loop. Inside of the player loop I'm doing this:

if ( checkUp() )
{
dbMoveSprite(PLAYER_SPRITE,2.0f);
}

if ( checkRight() )
{
dbRotateSprite(PLAYER_SPRITE,2.0f);
}

if ( checkLeft() )
{
dbRotateSprite(PLAYER_SPRITE,-2.0f);
}

I'm running into two problems. The sprite only rotates once and then stops no matter how many times i press or if i hold the left or right keys. The other problem is that the sprite seems to be rotating off-center. I'd like to have the sprite rotate in the middle.

Can anyone help? (fyi, the move command is working fine.)
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jan 2008 23:56
You'd probably be better off posting in the DGDK forums, but never mind.

First, take a look at the dbOffsetSprite function - this is used to specify the 'hotspot' of the sprite, which controls the rotation point and the positioning of the sprite relative to the coordinates you give it. Tinker around with it and you'll soon understand.

Next, the dbRotateSprite command sets the absolute rotation of the sprite, ie, it's not cumulative with earlier rotations. What you can do instead is use something like this to rotate:


The dbSpriteAngle gets the current angle of the sprite, then you add 2, then use dbWrapValue to ensure that the angle stays in the range of 0 to 360.

Robs
16
Years of Service
User Offline
Joined: 6th Jan 2008
Location: plano tx
Posted: 7th Jan 2008 03:06
Thanks IanM, that did it. I also used dbOffsetSprite and it worked like a charm.

Login to post a reply

Server time is: 2024-11-25 10:23:08
Your offset time is: 2024-11-25 10:23:08