//playerBall扩展动画类
//即使实体变为不可见,也会检测到碰撞
碰撞发生在实体分离前的位置
private void ballsR(){
registerUpdateHandler(new FPSLogger());
Random r = new Random();
int i= r.nextInt(7)+1;
if(count<1){
ballForColl[0] = ball;
count++;
System.out.println(count);
}
registerUpdateHandler(this.ballsDet = new TimerHandler(5.0f,true, new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
// TODO Auto-generated method stub
/* ball.setVisible(false);
ball.setIgnoreUpdate(true);
ball.detachSelf();
ball.clearUpdateHandlers();
@override*/
resourcesManager.engine.runOnUpdateThread(new Runnable() {
@Override
public void run() {
/* Now it is save to remove the entity! */
//pScene.detachChild(SpriteRemoveExample.this.mFaceToRemove);
detachChild((ball));
ball.setIgnoreUpdate(true);
}
});
// detachChild(ball);
// unregisterUpdateHandler(ball) ;
}
}));
/************************************************************/
//my player ball class
public playerBall(final float pX, final float pY, final TiledTextureRegion pTextureRegion,VertexBufferObjectManager vbom) {
super(pX, pY, pTextureRegion,vbom);
this.mPhysicsHandler= new PhysicsHandler(this);
this.registerUpdateHandler(this.mPhysicsHandler);
this.mPhysicsHandler.setVelocity(DEMO_VELOCITY, DEMO_VELOCITY);
// System.out.println("this is srs1");
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
if(this.mX < 0) {
// System.out.println("this is srs");
this.mPhysicsHandler.setVelocityX(DEMO_VELOCITY);
} else if(this.mX + this.getWidth() > 800) {
this.mPhysicsHandler.setVelocityX(-DEMO_VELOCITY);
}
if(this.mY < 0) {
this.mPhysicsHandler.setVelocityY(DEMO_VELOCITY);
} else if(this.mY + this.getHeight() > 480) {
this.mPhysicsHandler.setVelocityY(-DEMO_VELOCITY);
}
super.onManagedUpdate(pSecondsElapsed);
}
}
什么是"ball"?它是Sprite, AnimatedSprite, Circle…
它是否包含Body?
如果后者是真的,你可能忘记从物理世界中删除它…
试试这个:
final PhysicsConnector physicsConnector =
physicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(shape);
mEngine.runOnUpdateThread(new Runnable()
{
@Override
public void run()
{
if (physicsConnector != null)
{
physicsWorld.unregisterPhysicsConnector(physicsConnector);
body.setActive(false);
physicsWorld.destroyBody(bbody);
scene.detachChild(shape);
}
}
});