ScaleModifier makes sprite flicker

  ... tutorials on how to use AndEngine.

ScaleModifier makes sprite flicker

Postby bos » Sun Mar 04, 2012 3:01 am

I'm playing around and learning while making a splashscreen. I'm aware there's a class SplashScene, but as I'm learning I'm trying all kind of ways.

However, I can't seem to get this one right. The screen is 240x320 (W x H) and splash screen texture is 480x640 so i'm scaling it down to fit the screen. Texture loading etc is working fine, but when the sprite is shown I first see the large texture for 0.1secs, then it gets scaled down. I want it to get scaled down prior shown. Been trying everything, moved the call to attachChild() to onLoadComplete(), using setVisible(false), etc but I see the texture getting scaled down everytime.

Why?

Here's my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   @Override
  2.   public Scene onLoadScene() {
  3.     this.scene = new Scene();
  4.  
  5.     // Texture sizes
  6.     final int sX = mSplashTextureRegion.getWidth();
  7.     final int sY = mSplashTextureRegion.getHeight();
  8.  
  9.     // Center on camera
  10.     final int cX = (CAMERA_WIDTH - sX) / 2;
  11.     final int cY = (CAMERA_HEIGHT - sY) / 2;
  12.  
  13.     // Scale factor according to camera
  14.     final float scaleFactor = Math.min((float) CAMERA_WIDTH / sX, (float) CAMERA_HEIGHT / sY);
  15.  
  16.     // Init sprite
  17.     splashScreen = new Sprite(cX, cY, mSplashTextureRegion);
  18.     splashScreen.setVisible(false);
  19.    
  20.     // Rescale the splash-screen to fit the display, move it to (0, 0) and show it.
  21.     //splashScreen.registerEntityModifier(new ScaleAtModifier(0.001f, 1.0f, scaleFactor, 0, 0));
  22.     splashScreen.registerEntityModifier(new ScaleModifier(0.1f, 1.0f, scaleFactor));
  23. //    splashScreen.registerEntityModifier(new SequenceEntityModifier(
  24. //        new ScaleModifier(0.1f, 1.0f, scaleFactor),
  25. //        new DelayModifier(0.2f)
  26. //    ));
  27.    
  28.     return scene;
  29.   }
  30.  
  31.   @Override
  32.   public void onLoadComplete() {
  33.     scene.attachChild(splashScreen);
  34.     splashScreen.setVisible(true);
  35.   }
  36.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
bos
 
Posts: 44
Joined: Fri Jan 13, 2012 4:15 am

Re: ScaleModifier makes sprite flicker

Postby bos » Wed Mar 07, 2012 10:46 pm

Rewriting onLoadComplete() into this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   @Override
  2.   public void onLoadComplete() {
  3.     scene.attachChild(splashScreen);
  4.  
  5.     mHandler.postDelayed(korv, 1000);
  6.   }
  7.  
  8.   private Runnable korv = new Runnable() {
  9.     @Override
  10.     public void run() {
  11.       splashScreen.setVisible(true);
  12.  
  13.     }
  14.   };
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


removes the flicker, but that doesn't feel like a good solution.
bos
 
Posts: 44
Joined: Fri Jan 13, 2012 4:15 am

Re: ScaleModifier makes sprite flicker

Postby tajny » Thu Mar 08, 2012 1:32 am

You must work on floats not integers

Paweł P.

--------------------------------------
Portfolio

Run Santa Run Link
Xelorians Link
User avatar
tajny
 
Posts: 216
Joined: Mon May 30, 2011 10:23 pm
Location: Poland

Re: ScaleModifier makes sprite flicker

Postby bos » Thu Mar 08, 2012 7:42 am

?
bos
 
Posts: 44
Joined: Fri Jan 13, 2012 4:15 am


Return to Tutorials

Who is online

Users browsing this forum: Google Feedfetcher, rebeldev and 29 guests