Strange behaviour of scenes

  ... in the unlikely case you discovered a bug, post it here.

Strange behaviour of scenes

Postby Killi » Tue Nov 13, 2012 1:57 pm

Hi,

I made three games for now - and this never happened to me...the code is exactly the same (I used the same code to create a new game as quick as possible).
I'll try to describe my issue:
- I have two scenes - MainMenu + Game
- If I click on "play"-button in MainMenu I switch the scene with mEngine.setScene(Game)
- and now it's random!
Issue 1) Most of the time the screen is flickering between this two scenes - I can see the MainMenu and the Game! The game isn't finished yet so I'm never switching back to the MainMenu-scene! If I click on the screen (where my game buttons should appear) I hear the sounds of the game - so I know that the game scene is definately active!
Issue 2) I only see the game scene as expected. If a sprite should be set to visible I'll see this flickering like in issue 1 for this sprite.

It's hard to describe - so here you have 2 videos:

Issue 1 - switch to game scene


Issue 2 - set sprite visible on the top right corner


This never happened to me before - I really don't know what this could be...perhaps this bug: http://code.google.com/p/andengine/issues/detail?id=32 ?

Does this ever happened to anyone of you? What could that be? The only thing I do by clicking "play" is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private void newGame()
  2.         {
  3.                 pause = false;
  4.                 pauseSprite.setVisible(false);
  5.                
  6.                 doAnimate();
  7.  
  8.                 sandwich = new Vector<Integer>();
  9.  
  10.                 tablettSprite.setPosition(TABLETT_X, TABLETT_Y);
  11.                 doorLeftSprite.setPosition(DOOR_LEFT_X, DOOR_LEFT_Y);
  12.                 doorRightSprite.setPosition(DOOR_RIGHT_X, DOOR_RIGHT_Y);
  13.  
  14.                 bauplanFailSprite.setVisible(false);
  15.                 bauplanSuccessSprite.setVisible(false);
  16.                
  17.                 timer = 90.0f; // 1:30 min
  18.                 lastTimer = "";
  19.                 stage_end = false;
  20.  
  21.                 clearItem = false;
  22.                 sound_swipe_in_played = false;
  23.                 sound_swipe_out_played = false;
  24.                 clearItemNewItem = true;
  25.                 tablettDirection = -1;
  26.                
  27.                 level_money = 0;
  28.                 level_last_money = -1;
  29.                
  30.                 setLevel(1);
  31.                 newItem();
  32.                
  33.         mEngine.setScene(sceneGame);
  34.         }
  35.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


This only happens on my tablet (Android 4.0.3) - not on my phone (Android 4.1)
Killi
 
Posts: 26
Joined: Tue Jul 05, 2011 11:37 pm
Location: Winnenden, Germany

Re: Strange behaviour of scenes

Postby thepi » Tue Nov 13, 2012 5:19 pm

How do you attach MainMenu scene? If it's a child scene of sceneGame, try removing it with sceneGame.clearChildScene(); before calling the sceneGame scene.
Go and trap them... Trap Balls on Google Play
Play & reminisce... Treasure Island LCD Retro
thepi
 
Posts: 456
Joined: Sun Oct 09, 2011 9:30 pm

Re: Strange behaviour of scenes

Postby Killi » Tue Nov 13, 2012 6:26 pm

Here is the way I attach my scenes:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Main extends LayoutGameActivity {
  2.         // ===========================================================
  3.         // Constants
  4.         // ===========================================================
  5.         static int CAMERA_WIDTH = 1024;
  6.         static int CAMERA_HEIGHT = 640;
  7.        
  8.         static String TAG = "SandwichBar";
  9.        
  10.         // ===========================================================
  11.         // Fields
  12.         // ===========================================================
  13.  
  14.         private Random generator;
  15.         private Scene sceneSplash;
  16.         private Scene sceneMainMenu;
  17.         private Scene sceneGame;
  18.  
  19.         private GradientSprite mainmenu;
  20.         private GradientSprite gameBack;
  21.        
  22.         public void onLoadComplete() {
  23.         }
  24.        
  25.          protected int getLayoutID() {
  26.                  return R.layout.main;
  27.          }
  28.  
  29.          protected int getRenderSurfaceViewID() {
  30.                  return R.id.game_rendersurfaceview;
  31.          }
  32.  
  33.         public Engine onLoadEngine() {    
  34.             Camera mCamera = new Camera(0, 0, CAMERA_WIDTH,CAMERA_HEIGHT);
  35.             EngineOptions opts = new EngineOptions(
  36.                                 true,
  37.                                 ScreenOrientation.LANDSCAPE,
  38.                                 new FillResolutionPolicy(),
  39.                                 mCamera);
  40.             opts.setNeedsSound(true);
  41.             opts.setNeedsMusic(true);
  42.             opts.getRenderOptions().disableExtensionVertexBufferObjects();
  43.            
  44.             final Engine engine = new Engine(
  45.                         opts
  46.             );
  47.  
  48.             try {
  49.                     if(MultiTouch.isSupported(this)) {
  50.                                         engine.setTouchController(new MultiTouchController());
  51.                     }
  52.                 } catch (MultiTouchException e) {
  53.             }
  54.            
  55.             return engine;
  56.         }
  57.  
  58.         public void onLoadResources() {
  59.                 generator = new Random();
  60.         }
  61.        
  62.         private void unloadLoadingScene(){ }
  63.          
  64.         protected Scene onAssetsLoaded() {
  65.  
  66.                 //################################################ //
  67.                 //################## MAIN MENU ################## //
  68.                 //################################################ //
  69.                 sceneMainMenu = new Scene();
  70.                 sceneMainMenu.setOnAreaTouchTraversalFrontToBack();
  71.  
  72.                 mainmenu = new GradientSprite(0, 0, this.mFaceTextureRegionMainMenu);
  73.                 sceneMainMenu.setBackground(new SpriteBackground(mainmenu));
  74.                
  75.                 // Loaded + Added my buttons
  76.                 // [..]
  77.  
  78.                 sceneMainMenu.attachChild(mBtnPlay);
  79.                 sceneMainMenu.attachChild(mBtnInstructions);
  80.                 sceneMainMenu.attachChild(mBtnHighscore);
  81.                 sceneMainMenu.attachChild(mBtnAbout);
  82.                 sceneMainMenu.setTouchAreaBindingEnabled(true);
  83.                 sceneMainMenu.registerTouchArea(mBtnPlay);
  84.                 sceneMainMenu.registerTouchArea(mBtnInstructions);
  85.                 sceneMainMenu.registerTouchArea(mBtnHighscore);
  86.                 sceneMainMenu.registerTouchArea(mBtnAbout);
  87.                
  88.                
  89.                 //################################################ //
  90.                 //###################### GAME #################### //
  91.                 //################################################ //
  92.                 sceneGame = new Scene();
  93.                 sceneGame.setOnAreaTouchTraversalFrontToBack();
  94.  
  95.                 gameBack = new GradientSprite(0, 0, this.mFaceTextureRegionGame);
  96.                 sceneGame.setBackground(new SpriteBackground(gameBack));
  97.                
  98.                 // Loaded game stuff
  99.                 // [..]
  100.                
  101.                
  102.                 sceneGame.attachChild(slots);
  103.                 for (int iCnt = 0; iCnt < this.slot.length; iCnt++) {
  104.                         sceneGame.attachChild(slot[iCnt]);
  105.                 }
  106.                 sceneGame.attachChild(outdoorSprite);
  107.                 sceneGame.attachChild(doorLeftSprite);
  108.                 sceneGame.attachChild(doorRightSprite);
  109.                 sceneGame.attachChild(tablettSprite);
  110.                 for (int iCnt = 0; iCnt < this.slotBig.length; iCnt++) {
  111.                         sceneGame.attachChild(slotBig[iCnt]);
  112.                 }
  113.                 sceneGame.attachChild(bauplanFailSprite);
  114.                 sceneGame.attachChild(bauplanSuccessSprite);
  115.                 for (int iCnt = 0; iCnt < this.slotBigger.length; iCnt++) {
  116.                         sceneGame.attachChild(slotBigger[iCnt]);
  117.                 }
  118.                
  119.                 sceneGame.attachChild(ledBack);
  120.                 for (int iCnt = 0; iCnt < this.led.length; iCnt++) {
  121.                         sceneGame.attachChild(led[iCnt]);
  122.                 }
  123.                 sceneGame.attachChild(ledMiddle);
  124.                 for (int iCnt = 0; iCnt < this.money.length; iCnt++) {
  125.                         sceneGame.attachChild(money[iCnt]);
  126.                 }
  127.                 for (int iCnt = 0; iCnt < this.money_goal.length; iCnt++) {
  128.                         sceneGame.attachChild(money_goal[iCnt]);
  129.                 }
  130.                
  131.                 sceneGame.attachChild(pauseSprite);
  132.                 sceneGame.attachChild(mBtnPause);
  133.                 sceneGame.attachChild(mBtnPauseContinue);
  134.                 sceneGame.attachChild(mBtnPauseMainMenu);
  135.                 sceneGame.setTouchAreaBindingEnabled(true);
  136.                 for (int iCnt = 0; iCnt < this.slot.length; iCnt++) {
  137.                         sceneGame.registerTouchArea(slot[iCnt]);
  138.                 }
  139.                 sceneGame.registerTouchArea(mBtnPause);
  140.                 sceneGame.registerTouchArea(mBtnPauseContinue);
  141.                 sceneGame.registerTouchArea(mBtnPauseMainMenu);
  142.  
  143.                 sceneGame.registerUpdateHandler(new IUpdateHandler() {
  144.                         public void onUpdate(float pSecondsElapsed) {
  145.                                 onGameUpdate(pSecondsElapsed);
  146.                         }
  147.  
  148.                         public void reset() {                                          
  149.                         }
  150.                 });
  151.                
  152.                 return sceneMainMenu;
  153.         }
  154.        
  155.          
  156.         protected void assetsToLoad() {
  157.                
  158.                 // EMPTY BUTTONS
  159.                 this.mTextureButtons = new BitmapTextureAtlas(2, 2, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  160.                 this.mFaceTextureRegionButtons = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTextureButtons, this, "gfx/empty.png", 0, 0);
  161.                
  162.                 // MAIN MENU
  163.                 this.mTextureMainMenu = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  164.                 this.mFaceTextureRegionMainMenu = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTextureMainMenu, this, "gfx/mainmenu.png", 0, 0);
  165.  
  166.                 // GAME
  167.                 this.mTextureGame = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  168.                 this.mFaceTextureRegionGame = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTextureGame, this, "gfx/game.png", 0, 0);
  169.  
  170.                
  171.                 BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
  172.                 this.mEngine.getTextureManager().loadTextures(
  173.                         this.mTextureMainMenu,
  174.                         this.mTextureButtons,
  175.                         this.mTextureGame
  176.                 );
  177.         }
  178.        
  179.         public Scene onLoadScene() {
  180.                 this.mEngine.registerUpdateHandler(new FPSLogger());
  181.                
  182.  
  183.                
  184.                 //################################################ //
  185.                 //##################### SPLASH ################## //
  186.                 //################################################ //
  187.                 sceneSplash = new Scene();
  188.                 sceneSplash.setBackground(new ColorBackground(0, 0, 0));
  189.  
  190.                 // SPLASH
  191.                 this.mTextureSplash = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  192.                 this.mFaceTextureRegionSplash = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTextureSplash, this, "gfx/splash.png", 0, 0);
  193.  
  194.                 this.mEngine.getTextureManager().loadTextures(this.mTextureSplash);
  195.                 GradientSprite splashSprite = new GradientSprite(0, 0, this.mFaceTextureRegionSplash);
  196.                 splashSprite.setPosition(0,0);
  197.                 sceneSplash.attachChild(splashSprite);
  198.                
  199.                 IAsyncCallback callback = new IAsyncCallback() {
  200.                          
  201.                         public void workToDo() {
  202.                                 assetsToLoad();
  203.                         }
  204.  
  205.                         public void onComplete() {
  206.                                 unloadLoadingScene();
  207.                                 mEngine.setScene(onAssetsLoaded());
  208.                         }
  209.                 };
  210.  
  211.                 new AsyncTaskLoader().execute(callback);
  212.  
  213.                 return sceneSplash;
  214.         }
  215.        
  216.        
  217.         private void onGameUpdate(float pSecondsElapsed)
  218.         {
  219.                 // Do game stuff
  220.         }
  221.        
  222. }
  223.  
Parsed in 0.019 seconds, using GeSHi 1.0.8.4
Killi
 
Posts: 26
Joined: Tue Jul 05, 2011 11:37 pm
Location: Winnenden, Germany

Re: Strange behaviour of scenes

Postby thepi » Wed Nov 14, 2012 8:36 am

What I think is if you make Menu scene child of your Game scene, then there can be no flickering between those scenes.

Also check this thread, it seems to be something similar to yours:
development/problems-loading-resources-in-background-t4778.html

On the other hand, there is still a simple solution to get a static splash screen, without async threads:
tutorials/very-simple-splash-screen-alternative-t5790.html
Go and trap them... Trap Balls on Google Play
Play & reminisce... Treasure Island LCD Retro
thepi
 
Posts: 456
Joined: Sun Oct 09, 2011 9:30 pm

Re: Strange behaviour of scenes

Postby Killi » Wed Nov 14, 2012 8:33 pm

Ok, 1000 thanks for this tip!

Now I changed my async loader to the loading-way you postet. I'm not getting this flickering any more! Very strange why this happened, but thank you!

BUT..... ;-)

Now I'm getting following error:

11-14 19:20:34.940: W/nvwsi(22612): dequeueBuffer failed, error -22

I found absolutely nothing about this in google - I only found a notice that this has to do with rendering.
I thought I have too much sprites using the same textures, so I copied the png files so any texture loads isown file...but it's exactly the same :-(

The code which is commented caused this error:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
  2.                 this.mEngine.getTextureManager().loadTextures(
  3.                         this.mTextureMainMenu,
  4.                         this.mTextureButtons,
  5.                         this.mTextureGame,
  6.                         this.mTextureSlots,
  7.                         this.mTextureSlot[0],
  8.                         this.mTextureSlot[1],
  9.                         this.mTextureSlot[2],
  10.                         this.mTextureSlot[3],
  11.                         this.mTextureSlot[4],
  12.                         this.mTextureSlot[5],
  13.                         this.mTextureSlot[6],
  14.                         this.mTextureSlot[7],
  15.                         this.mTextureSlot[8],
  16.                         this.mTextureSlot[9],
  17.                         this.mTextureSlot[10],
  18.                         this.mTextureSlot[11],
  19.                         this.mTextureSlot[12],
  20.                         this.mTextureSlot[13],
  21.                         this.mTextureSlot[14],
  22.                         this.mTextureSlot[15],
  23.                         this.mTextureSlot[16],
  24.                         this.mTextureSlot[17],
  25.                         this.mTextureSlotBig[0],
  26.                         this.mTextureSlotBig[1],
  27.                         this.mTextureSlotBig[2],
  28.                         this.mTextureSlotBig[3],
  29.                         this.mTextureSlotBig[4],
  30.                         this.mTextureSlotBig[5],
  31.                         this.mTextureSlotBig[6],
  32.                         this.mTextureSlotBig[7],
  33.                         this.mTextureSlotBig[8],
  34.                         this.mTextureSlotBig[9],
  35.                         this.mTextureSlotBig[10],
  36.                         this.mTextureSlotBig[11],
  37.                         this.mTextureSlotBig[12],
  38.                         this.mTextureSlotBig[13],
  39.                         this.mTextureSlotBig[14],
  40.                         this.mTextureSlotBig[15],
  41.                         this.mTextureSlotBig[16],
  42.                         this.mTextureSlotBig[17],
  43.                 /*      this.mTextureSlotBigger[0],
  44.                         this.mTextureSlotBigger[1],
  45.                         this.mTextureSlotBigger[2],
  46.                         this.mTextureSlotBigger[3],
  47.                         this.mTextureSlotBigger[4],
  48.                         this.mTextureSlotBigger[5],
  49.                         this.mTextureSlotBigger[6],
  50.                         this.mTextureSlotBigger[7],
  51.                         this.mTextureSlotBigger[8],
  52.                         this.mTextureSlotBigger[9],
  53.                         this.mTextureSlotBigger[10],
  54.                         this.mTextureSlotBigger[11],
  55.                         this.mTextureSlotBigger[12],
  56.                         this.mTextureSlotBigger[13],
  57.                         this.mTextureSlotBigger[14],
  58.                         this.mTextureSlotBigger[15],
  59.                         this.mTextureSlotBigger[16],
  60.                         this.mTextureSlotBigger[17],*/
  61.                         this.mTexturePause,
  62.                         this.mTexturePauseBtn,
  63.                         this.mTextureTablett,
  64.                         this.mTextureOutdoor,
  65.                         this.mTextureDoorLeft,
  66.                         this.mTextureDoorRight,
  67.                         this.mTextureLedBack,
  68.                         this.mTextureLed[0],
  69.                         this.mTextureLed[1],
  70.                         this.mTextureLed[2],
  71.                         this.mTextureLed[3],
  72.                         this.mTextureLedMiddle,
  73.                         this.mTextureMoney[0],
  74.                         this.mTextureMoney[1],
  75.                         this.mTextureMoney[2],
  76.                         this.mTextureMoney[3],
  77.                         this.mTextureMoneyGoal[0],
  78.                         this.mTextureMoneyGoal[1],
  79.                         this.mTextureMoneyGoal[2],
  80.                         this.mTextureMoneyGoal[3],
  81.                         this.mTextureBauplanFail,
  82.                         this.mTextureBauplanSuccess
  83.                 );
  84.  
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
Killi
 
Posts: 26
Joined: Tue Jul 05, 2011 11:37 pm
Location: Winnenden, Germany

Re: Strange behaviour of scenes

Postby Killi » Wed Nov 14, 2012 8:41 pm

EDIT: it's ok now, I use the same texture as (slotsBig) for the other Sprite.
But I have to do a trick - because it's a TiledSprite. And every time I change the current tile index the other changed, too.

It's ok now...but.....I really want to know what causes this dequeue error?!
Killi
 
Posts: 26
Joined: Tue Jul 05, 2011 11:37 pm
Location: Winnenden, Germany


Return to Bugs

Who is online

Users browsing this forum: No registered users and 3 guests