0
저는 AndEngine/Box2D를 사용하여 게임을 만듭니다. 게임이로드되면 스프라이트와 본문을 포함하는 클래스의 배열이 만들어집니다. 사용자가 화면을 터치하면 순서대로 다음 스프라이트가 장면에 첨부되고 본문이 활성화로 설정됩니다. 스프라이트/바디는 나중에 파괴 될 수 있습니다. 이렇게하려면 스프라이트를 분리하고 본문을 비활성으로 설정합니다. 그러나 그 시점에서 장면은 더 이상 터치를 등록하지 않습니다. 스프라이트/바디를 패스로 드래그하면 멈 춥니 다. 그러나 장면의 다른 몸체는 상호 작용하지 않습니다. 이것은 나를 그것이 터치 오류와 관련이 있다고 믿게합니다. 여기 내 코드입니다 :화면에 스프라이트/바디가 제거 된 터치가 등록되지 않습니까 (Box2D)?
private void destroyFiller(){ //Deletes filler
if(filler[fillerNum].active){
filler[fillerNum].active=false;
mPhysicsWorld.unregisterPhysicsConnector(mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(filler[fillerNum].sprite));
filler[fillerNum].body.setUserData("destroy");
scene.detachChild(filler[fillerNum].sprite);
fillerCount--;
fillersLeftText.setText("Balls left: "+Integer.toString(fillerCount));
if(fillerCount==0)
gameOver();
}
}
하고 설정 어디 몸이 장면 터치 이벤트
scene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
}
@Override
public void onUpdate(float pSecondsElapsed) {
if(fillerNum>-1){
if(filler[fillerNum].body.getUserData().equals("destroy")){ //"Destroys" the body which can only be done on an update
filler[fillerNum].body.setActive(false);
filler[fillerNum].body.setUserData("destroyed");
if(soundOn)
popSound.play();
}
비활성 : 필요한 경우
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if(this.mPhysicsWorld != null && mEngine != null) {
if(pSceneTouchEvent.isActionDown()) {
Log.e("SceneTouchEvent","Touch"); //This line doesn't execute when touching a body that passed through destroyFiller
createFiller(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
return true;
}
}
return false;
}
그리고 createFiller :
private void createFiller(float x, float y) {
fillerNum++;
filler[fillerNum].active=true;
filler[fillerNum].sprite.setPosition(x-fillerTR.getWidth()/2,y - fillerTR.getHeight()/2);
scene.registerTouchArea(filler[fillerNum].sprite);
filler[fillerNum].body.setUserData("fill");
filler[fillerNum].body.setActive(true);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(filler[fillerNum].sprite, filler[fillerNum].body, true, true));
scene.attachChild(filler[fillerNum].sprite);
}