Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the Rotating Sprites tutorial. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
Didn't know ctrl-s posted my message. Anyway, my question related to this prematurely posted code is this:
When I draw this Object2D and add rotation, it rotates clockwise when the value of Rotation goes up. That is:
rotates it clockwise.
For drawing code I use:
inside the same class (Object2D)
Now is this how it should behave? I've always thought that a increase in the radian value of a rotation rotates it counter-clockwise. Conversely, when I decrease the Object2D's rotation ( -= 0.05f) the object indeed rotates counter-clockwise, though I would expect it to rotate clockwise.
Am I missing some important point here?
Anyway, I hope you get to see this, since in your last update you said to not have much time in the coming months until March. It is now March though :).
Yep. It's March. I'm still finishing up though. I'm currently working full time and trying to finish up a master's degree, and it is quite a bit of work. I was hoping to finish my thesis by the beginning of March, but here it is, nearing the end, and I've still got just a little bit more to go. Two or three weeks more and I'll be done. That will free up a ton of time, once it is over!
Anyway, about your question. No, it is not normal for it to ALWAYS rotate counterclockwise. If you give it a positive value, it should rotate clockwise. If you give it a negative value, it should rotate counterclockwise. I'm not sure why exactly yours is behaving so strangely, though my first thought is that it is likely in the way you are handling rotation within your Object2D class. My second thought is that it could possibly be interacting strangely with your GetPositionRectangle() method, but that doesn't seem too likely to me.
If you haven't gotten it working on your own yet, then maybe you can post the code for your entire Object2D class?
Anyway, here's some sample code that I made to play around with what you were saying. It seems to be working correctly with two angles (one positive, and the other negative).
Hope that helps!
How about moving the sprite based on it's rotation? ie pushing up, sends the sprite in it's forward direction????
Im having major troubles with this atm
Yes.. I would also like help with this, I have my shuttle rotate on left and right arrows but i am having trouble with the foward and back part.
See my answer below. I just added it.
The real challenge for me with answering questions like this is that everybody is going to want to do things differently. It really depends on the game you're working on, and when it comes down to it, you'll probably end up needing to figure some of the details out on your own.
Having said that, I get enough questions where people get hung up at about this point that it is probably worth showing a more complete example. Ideally, that would be a complete tutorial set that shows the process of making a simple game like Asteroids or something. That's in the plans, but as of the beginning of April 2012, I don't have that done yet. It's at the top of my priority list, though, I promise! So the next best thing is a small example, showing one possible way to turn user input into a moving, rotating sprite.
Note that this example pulls in stuff from the keyboard input tutorial, and if you haven't done anything in that tutorial you should. It would be pretty easy to modify this to use the Xbox controller, and in fact, you could use how far the thumbstick is moved to influence how fast you should turn or move.
The real trick is to figure out how the ship's angle affects movement in the x and y directions. Essentially, you're working in polar coordinates (speed and direction) and you want to convert it to cartesian (x and y) coordinates. The key part of my code does this:
The complete code looks like this:
Thanks..
No problem!
Post preview:
Close preview