Note that there are some explanatory texts on larger screens.

plurals
  1. PORotating an image gradually from one degree to another
    primarykey
    data
    text
    <p>This is my first post, so please bear with me. I'll try and be as clear as I can here about my problem. First off, let me say that I suck at math. I failed it in school, and it pains me to no end that I can't grasp simple math concepts, especially since I love to code. Someone who wants to program, and can't perform basic math operations? Bad combo. Aaaanyway, on to the problem.</p> <p>Some context. I am writing an asteroids-type game. It's coming along quite nicely, and I've overcome all my hurdles so far thanks to this site (thank you!), and google. I've searched high and low to a solution to my problem, but it always seems like I run into a solution that either doesn't work, or I just don't understand and can't incorporate it into my code.</p> <p>The issue involves rotation of the ship. I have an onscreen joystick class that returns the angle that the joystick is being pushed. I use that angle to point the ship in that same direction. </p> <p>What I want to do is <em>gradually</em> turn the ship towards the angle the user wants to go, using the shortest turn, left or right. In my mind I'm thinking "How the hell do I go to say.. 350 degrees from 5 degrees, going left?". I don't know...</p> <p>Here is my draw code:</p> <pre><code>public void draw(Canvas canvas){ canvas.save(); canvas.rotate((float) (fAngle + 90), (float) (dX + (mShip.getIntrinsicWidth() / 2)), (float) (dY + (mShip.getIntrinsicHeight() / 2))); mShip.setBounds((int)dX, (int)dY, (int)dX + mShip.getIntrinsicWidth(), (int)dY + mShip.getIntrinsicHeight()); mShip.draw(canvas); canvas.restore(); } </code></pre> <p>The angle is passed to the fAngle variable from the joystick getangle method. The angle is then increased by 90 degrees because of the image facing. </p> <pre><code>user.fAngle = oJoystick.getAngle(); </code></pre> <p>So on each game tick, I want to turn the ship towards whatever direction the player wants to go, degree by degree. Any help with this would be greatly appreciated! </p> <p>Thanks for reading!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload