How to get the current angle of a sprite in Cocos2d v3 - cocos2d-iphone

I am wanting to move a sprite in the the direction it is facing. I got everything I need except the sprites current angle. It is rotating back and forth like a pendulum forever, but when the button that moves it is tapped it stops rotating and moves in the direction it is currently facing, or at least thats what I want it to do, but I don't know how to get the value for the current angle. Could someone help me out? =)

Related

Accelometer different sensitivity at different tilts?

In my cocos2d game I would like to use tilt controls. The game is in landscape left only, for keeping it simple.
Now, if the user tilt device backwards, eg, tilt the screen upwards, the player sprite is moving up(+y). If the tilt is in the other direction(turning screen downwards) the sprite moves down. -(y)
The problem is that the device is pretty much in downward tilt from start and the player sprite moves down quickly. To get it moving up I have to tilt the device so far that I canĀ“t see the screen.
So is there anyway to make the tilt less/more sensitive based on what direction the said tilt is?
You need to set a filtering factor for this. Take a look at the tutorial at http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game which goes through how to use the accelerometer for this type of movement.

How can I move a ball in Cocos2D,Box2D like flicking a real ball, with touches?

I am trying to learn box2d in cocos2d. I have searched for online tutorials and ray Wenderlich's seem to be the best ones!I am learning in a slow but steady pace! I am currently developing an app in which I will include a ball in the screen, and every time I touch/tap this ball, it is going to move like someone is flicking a soccer ball. I have coded the part for the upward movement(y axis) of the ball, when touching/tapping it. The problem that I encounter is that I can not find a way to give the ball the appropriate angle in order to rotate and move on the x axis. Let me give you an example. Imagine you are flicking a soccer ball, you kick the ball upwards but also there is a spinning force on the ball. I am trying to develop the spinning and moving across the x axis part. I would like to touch the ball, in its lower right "corner" for example and spin and move in a realistic way. Touching it in the lower right "corner" while the ball is in the air, means that the ball will move and spin to the left side of the screen. I hope I clarified the situation! I would be grateful if someone could help me to understand that kind of movement! If you still haven't understand the concept of my game, search for "parksoccer" and you will understand what I am trying to develop.
I did this yesterday only. In this case what you can do is when you touch or tap a screen , you take that point in ccTouchesBegan and then find the position of the ball by GetPostion() method on body. Than you have to calculate the angle between these two points and find in which direction ball will go from these two points. now you have angle and direction in which ball will go so apply linearForce on that by ApplyLinearForce(b2vec2 forceangle, body->GetPosition()). Thats it.
Enjoy.

determining when a body attached to a rope has moved a specific distance

Using Cocos2d and Box2d I have made a rope of revolute joint segments with a body attached to the lowest segment (weldJoint) which I move using a mouse joint. The rope is hanging downward. How can I set conditions to tell when the attached body has covered double the distance it is swiped (mouseJoint) in the opposite direction. For example, if I swipe the body (attached to the rope) 45 degrees to the left I should know (maybe by some message or something) when it swings back 45 degrees to the right. Please help.
Perhaps I'm oversimplifying, but have you tried adding a sensor (Section 6.3 of Box2dManual) when you release it? If your physics are pretty simple, you should be able to get away with adding it at the same Y as the release point and making it's X flipped about the joint location.

Cocos2d Joystick

I have been looking all over for help on how to make a CCSprite move and rotate with the movement of a virtual joystick. I have tried examples and sample code, but, none have worked for me. If someone could tell me how to implement a joystick into the HelloWorld layer, that would be wonderful. P.S. The joystick does not need to move the sprite with variable velocity, it just needs to move it in a direction at a constant speed.
Thanks in advance.
First of all, this is a poorly worded question. Normally I would vote you down for this but for some reason I am not going to today.
You say there is no need for variable velocity, but it needs to move in a direction at a constant speed. I assume then that you need a full 360 degree range. What you do is have a joypad sprite on your layer. When you touch the sprite you calculate the angle of the touch (ignoring distance from center since you don't care about variable velocity). Convert the angle to a CGPoint ( ccpForAngle(CGFloat) is helpful for that ) and then use ccpMult(CGPoint, CGFloat) to decide how fast to move your sprite. Then you can use CCMoveBy to move your sprite.
That's one way of doing it at least.

Trying to implement a mouse look "camera" in OpenGL/SFML

I've been using OpenGL with SFML 1.6 for some time now, and it has been a blast! With one exception: I can't seem to implement a camera class correctly. You see, I am trying to create a C++ class called "Camera". Here are my functions:
Camera::Strafe(float fSpeed)
checks whether the WASD keys are pressed, and if so, move the camera at "fSpeed" in their respective directions.
Camera::MouseMove(int currentX, int currentY)
should provide a first-person mouse look, taking in the current mouse coordinates and rotating the camera accordingly. My Strafe() implementation works fine, but I can't seem to get MouseMove() right.
I already know from reading other resources on OpenGL mouse look implementations that I must center the mouse after every frame, and I have that part down. But that's about it. I can't seem to get how to actually rotate the camera on the spot from the mouse coordinates. Probably need to use some trig, I bet.
I've done something similar to this (it was a 3rd person camera). If I remember what I did correctly, I took the change in mouse position and used that to calculate two angles (I did that with some trig, I believe). One angle gave me horizontal rotation, the other gave me vertical rotation. Pitch, Yaw and Roll specifically, although I can't remember which refers to which direction. There is also one you have to do before the other, or else things will rotate funny. I'm pretty sure it was pitch first, then yaw or roll.
Hopefully it should be obvious what the change in mouse position did. It allowed mouse senesitivity. If I moved the mouse fast, I would have a larger change, and so I would rotate "faster."
EDIT: Ok, I looked at my code and it's a very simple calculation.
This was done with C#, so bear with me for syntax:
_angles.X += MathHelper.ToDegrees(changeInX / 100);
_angles.Y += MathHelper.ToDegrees(changeInY / 100);
my angles were stored in a 2 dimensional vector (since I only rotated on two axes). You'll see I took my changeInX and changeInY values and simply divided them by 100 to get some arbitrary radian value, then converted that number to degrees. Adjust the 100 for sensitivity. Keep in mind, no solid-math was done here to figure this out. I just did some trial-and-error until I got something that worked well.