嘿伙计们关注此代码
final AnimatedSprite mySprite = new AnimatedSprite(100, 220, this.mySpriteTextureRegion) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
int eventaction = event.getAction();
float X = event.getX();
float Y = event.getY();
switch (eventaction) {
case TouchEvent.ACTION_DOWN:
break;
case TouchEvent.ACTION_MOVE: {
this.setPosition(X, Y);
break;}
case TouchEvent.ACTION_UP:
break;
}
return true;
}
};
但使用Sprite而不是AnimatedSprite
但是当我在我的手机上测试时,精灵不会移动......
我做错了什么?
答案 0 :(得分:1)
你错过了吗?
registerTouchArea(mySprite);
setTouchAreaBindingOnActionDownEnabled(true);