当点击And Engine游戏中的屏幕时,如何上下移动附加身体的精灵?我有一个精灵球作为一个身体,我想在用户触摸屏幕时上下移动..
ball=new PixelPerfectSprite(mCamera.getWidth()/10,mCamera.getHeight()/2-70, mResourceManager.ball,vbom);
mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);//ball as a body
final FixtureDef ballFixtureDef = PhysicsFactory.createFixtureDef(10f,0.5f,0);
ballbody = PhysicsFactory.createCircleBody(mPhysicsWorld, ball, BodyType.DynamicBody, ballFixtureDef);
ballbody.setUserData("ball");
pc=new PhysicsConnector(ball, ballbody,true,false);
registerUpdateHandler(new IUpdateHandler(){
@Override
public void onUpdate(float pSecondsElapsed) {
// TODO Auto-generated method stub
if(ballmove==true){
mPhysicsWorld.registerPhysicsConnector(pc);
ballbody.setLinearVelocity(0,5f);
}
if(ball.getY()>=mCamera.getHeight()/2+70){
}
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
});
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
ballmove=true;
return false;
}
答案 0 :(得分:0)
有很多选择可以完成这项工作。最简单的就是使用Linear Velocity。所以,基本步骤是: