TouchEventPool <touchevent>用尽了</touchevent>

时间:2014-07-21 11:27:12

标签: android andengine ontouchevent

在对元素(精灵)进行一些触摸之后(首先它工作正常,但在Logcat中有如下所示的消息)我已经冻结(元素停止对touchevent做出反应)。 应用程序没有崩溃,只是没有反应触摸

    07-20 00:12:25.822: V/AndEngine(9003):         org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 21 item     not yet recycled. Allocated 1 more. 
    07-20 00:12:25.822: V/AndEngine(9003):     org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted,    with 21 item not yet recycled. Allocated 1 more. 

Main.java

    public class Main extends SimpleBaseGameActivity implements ICallBack_2  {
    public static Scene mainScene;

    private cBigTile bigTile;
    private Sprite   pauseButton;

@Override
public EngineOptions onCreateEngineOptions() {      
    mainCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    return new EngineOptions(false, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), mainCamera); 
}

@Override
public void onCreateResources() {        
    bigTile = new cBigTile(0, 0, decoratedTextureRegion, getVertexBufferObjectManager(), getTextureManager(), getAssets(), getFontManager(), this);

    pauseButton = new Sprite(0,0,decoratedTextureRegion_3, getVertexBufferObjectManager()) {
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.isActionDown()) {  
                return true;  
            }          
            return false;
        };
    };      
}

@Override
    public Scene onCreateScene() {
    mainScene = new Scene();
    mainScene.setBackground(new Background(242f/255f, 246f/255f, 232f/255f));    

    for (int i = 0;i<9;i++) mainScene.registerTouchArea(((cTile)bigTile.getChildByIndex(i)).sprite);
    mainScene.registerTouchArea(pauseButton);

    return mainScene;
}

}

cBigTile.java

    public class cBigTile extends Sprite implements ICallBack_1 {

    private cTile[] tiles;

    public cBigTile(float pX, float pY, ITextureRegion pTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, TextureManager _textureManager, AssetManager _assetManager, FontManager _fontManager, ICallBack_2 _parent) {
            super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
            for (int i = 0;i<9;i++) {
                    tiles[i] = new cTile(rectSize, rectSize, _textureManager, pVertexBufferObjectManager, font, this, i);
                    this.attachChild(tiles[i]);
            }              
    }

}

cTile.java

    public class cTile extends Entity {
    public Sprite sprite;

    public cTile(int _width, int _height, TextureManager _textureManager, VertexBufferObjectManager _vbo, Font _font, ICallBack_1 _parent, int _index) {
            super();
    sprite = new Sprite(0, 0, decoratedTextureRegion, vbo) {
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pSceneTouchEvent.isActionDown()) {
                parent.onTileClicked(presentValue, index);
                return true;  
            }          
            return false;
        };
    };
    this.attachChild(sprite);

    }

}

0 个答案:

没有答案