Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 416697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:30:22+00:00 2026-05-12T18:30:22+00:00

I’m using Dark GDK and C++ to create a simple 2d game. I’m rotating

  • 0

I’m using Dark GDK and C++ to create a simple 2d game. I’m rotating an object but it rotates from the top left corner of the sprite.

I have the following variables available:

  • PlayerX
  • PlayerY
  • PlayerWidth
  • PlayerHeight
  • RotateAngle (360 > x > 0)

Is there an algorithm that will modify the pivot point of the sprite, preferable to the center?

Here is a small code sample:

void Player::Move( void )
{

    if ( checkLeft() )
    {
        PlayerX -= PlayerSpeed;
        if ( PlayerX < 0 )
            PlayerX = 0;
    }

    if ( checkRight() )
    {
        PlayerX += PlayerSpeed ;
        if ( PlayerX > 800 - PlayerWidth )
            PlayerX = 800 - PlayerWidth;
    }

    if ( checkUp())
    {
        PlayerY -= PlayerSpeed;
        if ( PlayerY < 0 )
            PlayerY = 0;
    }

    if ( checkDown())
    {
        PlayerY += PlayerSpeed;
        if ( PlayerY > 600 -  PlayerHeight)
            PlayerY = 600 - PlayerHeight;
    }

    RotateAngle += 5;
    if(RotateAngle > 360)
        RotateAngle -=360;

    dbRotateSprite(Handle,RotateAngle);
    dbSprite ( 1 , PlayerX , PlayerY , Handle );
}

Edit

I’m considering opening up some reputation for this question, I have yet to be provided with an answer that works for me. If someone can provide an actual code sample that does the job, I’d be very happy.

The problem with Blindy’s answer is that no matter how much I simply translate it back or forth, the spirte still rotates around the top left hand corner and moving it somewhere rotating around the top left corner, then moving it back to the same position accomplishes nothing. Here is what I believe to be going on:

alt text http://img248.imageshack.us/img248/6717/36512474.png

Just so there is no confusion I have created a an image of what is going on. The left shows what is actually happening and the right shows what I need to happen.

alt text http://img101.imageshack.us/img101/1593/36679446.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:30:22+00:00Added an answer on May 12, 2026 at 6:30 pm

    The answers so far are correct in telling you how it should be done but I fear that the Dark GDK API seems to be too primitive to be able to do it that simple way.

    Unfortunately dbRotateSprite rotates the sprite about the top left regardless of the sprite’s transform which is why you’re having no luck with the other suggestions. To simulate rotation about the centre you must manually correct the position of the sprite i.e. you simply have to rotate the sprite and then move it as a two-step process.

    I’m not familiar with the API and I don’t know if y is measured up or down and which way the angle is measured so I’m going to make some assumptions. If y is measured down like many other 2D graphics systems, and the angle is measured from the x-axis increasing as it goes from the positive x-axis to the positive y-axis, then I believe the correct psuedo-code would look like

    // PlayerX and PlayerY denote the sprite centre
    // RotateAngle is an absolute rotation i.e. not a relative, incremental rotation
    
    RotateAngle += 5;
    RotateAngle %= 360;
    RadiansRotate = (RotateAngle * PI) / 180;
    
    dbRotateSprite( Handle, RotateAngle );
    
    HalfSpriteWidth = dbSpriteWidth( Handle ) / 2;
    HalfSpriteHeight = dbSpriteHeight( Handle ) / 2;
    
    SpriteX = PlayerX
            - HalfSpriteWidth * cos(RadiansRotate)
            + HalfSpriteHeight * sin(RadiansRotate);
    SpriteY = PlayerY
            - HalfSpriteHeight * cos(RadiansRotate)
            - HalfSpriteWidth * sin(RadiansRotate);
    
    // Position the top left of the sprite at ( SpriteX, SpriteY )
    dbSprite ( 1 , SpriteX , SpriteY , Handle );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.