我不知道为什么,但这部分代码正在改变我的变量:toMovePosition
bodyNpc.setLinearVelocity(toMovePosition.sub(bodyNpc.getPosition()).nor());
代码:
private void createPhysics(final Camera camera, PhysicsWorld physicsWorld) {
// TODO Auto-generated method stub
bodyNpc = PhysicsFactory.createCircleBody(physicsWorld, this, BodyType.KinematicBody, PhysicsFactory.createFixtureDef(0, 0, 0));
bodyNpc.setUserData("N" + ArrayPosition);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, bodyNpc, true, false)
{
@Override
public void onUpdate(float pSecondsElapsed)
{
super.onUpdate(pSecondsElapsed);
if(toMovePosition != null){ //Si te on anar
bodyNpc.setLinearVelocity(toMovePosition.sub(bodyNpc.getPosition()).nor());
Log.w("Npc", ""+toMovePosition);
}
}
});
}
变量:
public Body bodyNpc;
private Vector2 toMovePosition;
获取器和设置器:
public void setToMovePosition(float px, float py){
this.toMovePosition = new Vector2(px, py);
}
public Vector2 getToMovePosition(){
return this.toMovePosition;
}
谢谢。