简体   繁体   中英

Hide and show sprites andengine Android

I have a little problem/question... I want to hide one sprite and show another one but eclipse gives me error "The local ... may not have been inatialized". Unfortunatelly I don't have another idea to hide and show those sprites... Can anybody help me? Code:

protected Scene onCreateScene() {

    final Scene scene = new Scene();
    Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
    scene.attachChild(backgroundSprite);

    final Katapulta S_katapulta_wystrzelona = new Katapulta(10, 300, this.mKatapulta_wystrzelona, getVertexBufferObjectManager());

    final Katapulta S_katapulta_zaladowana = new Katapulta(10, 300, this.mKatapulta_zaladowana, getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

    // IN THIS LINE I HAVE ERROR    S_katapulta_zaladowana.setVisible(false);


            S_katapulta_wystrzelona.setVisible(true);

            return true;
        }
    };

    scene.attachChild(S_katapulta_zaladowana);

    scene.attachChild(S_katapulta_wystrzelona);
    S_katapulta_wystrzelona.setVisible(false);

    scene.registerTouchArea(S_katapulta_zaladowana);

    return scene;
}

Just use setVisible(false); instead of S_katapulta_zaladowana.setVisible(false); Because of the way you used the onAreaTouched() method.

尝试添加它。

setOnSceneTouchListener(this); 

尝试将tag设置为所有sprites。然后使用tag调用sprite,然后使其不可见

You have to initialize the variable so that it is actually pointing to something it can use

ie;

int x = new int;
x = 69;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM