How to rotate a sprite using multi-touch with AndEngine?
Posted
by
786
on Game Development
See other posts from Game Development
or by 786
Published on 2012-11-21T13:25:20Z
Indexed on
2012/11/28
17:20 UTC
Read the original article
Hit count: 293
I am new to Android game development. I am using AndEngine GLES-2. I have created a box with a sprite. This box is now draggable by using the code below. It works fine.
But I want multi-touch on this: I want to rotate the sprite with two fingers on that box, and to keep it draggable.
I've no idea how do do that, which way should I go?
final float centerX = (CAMERA_WIDTH - this.mBox.getWidth()) / 2;
final float centerY = (CAMERA_HEIGHT - this.mBox.getHeight()) / 2;
Box = new Sprite(centerX, centerY, this.mBox, this.getVertexBufferObjectManager()) {
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() - this.getWidth()/ 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
float pValueX = pSceneTouchEvent.getX();
float pValueY = CAMERA_HEIGHT-pSceneTouchEvent.getY();
float dx = pValueX - gun.getX();
float dy = pValueY - gun.getY();
double Radius = Math.atan2(dy,dx);
double Angle = Radius * 360 ;
Box.setRotation((float)Math.toDegrees(Angle));
return true;
}
© Game Development or respective owner