2013-08-21 53 views
0

嗨即時嘗試讓淡入淡出和縮小後淡出和縮小。爲此,我使用了Entitiy修飾符偵聽器,但它不工作?繼承人我的代碼:淡入淡出後讓雪碧淡入? Entitiy Modifier

public class GameScene { 

Scene gameScene; 
Engine engine; 
Activity activity; 

BitmapTextureAtlas mTextureAtlas; 
ITextureRegion X; 
ITextureRegion O; 
ITextureRegion XO; 

FadeInModifier fadeIn = new FadeInModifier(2); 
FadeOutModifier fadeOut = new FadeOutModifier(2); 
ScaleModifier scaleDown = new ScaleModifier(3, 1, 0); 
ScaleModifier scaleUp = new ScaleModifier(2, 0, 1); 

Sprite XOsprite; 
Random rand = new Random(); 
boolean XYset = false; 

public GameScene(Engine eng, Activity act) { 
    engine = eng; 
    activity = act; 
} 

public Scene getScene() { 

    gameScene = new Scene(); 
    gameScene.setBackground(new Background(0, 256, 59)); 
    int x = 0, y = 0; 

    if (rand.nextInt(2) == 0) { 
     XO = X; 
    } else { 
     XO = O; 
    } 

    if (!XYset) { 
     x = rand.nextInt(MainActivity.CAM_WIDTH); 
     y = rand.nextInt(MainActivity.CAM_HEIGHT); 
     XYset = true; 
    } 



    XOsprite = new Sprite(x, y, XO, engine.getVertexBufferObjectManager()) { 
     @Override 
     public boolean onAreaTouched(final TouchEvent te, final float xVal, 
       final float yVal) { 
      XOsprite.registerEntityModifier(fadeOut); 
      XOsprite.registerEntityModifier(scaleDown); 
      return true; 

     } 
    }; 
    IEntityModifierListener fadeOutListener = new IEntityModifierListener() { 

     @Override 
     public void onModifierStarted(IModifier<IEntity> pModifier, 
       IEntity pItem) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onModifierFinished(IModifier<IEntity> pModifier, 
       IEntity pItem) { 
      // TODO Auto-generated method stub 
      XOsprite.clearEntityModifiers(); 
      XOsprite.setPosition(rand.nextInt(MainActivity.CAM_WIDTH), rand.nextInt(MainActivity.CAM_HEIGHT)); 
      XOsprite.registerEntityModifier(fadeIn); 
      XOsprite.registerEntityModifier(scaleUp); 
     } 
    }; 
    fadeOut.addModifierListener(fadeOutListener); 
    XOsprite.registerEntityModifier(scaleUp); 
    XOsprite.registerEntityModifier(fadeIn); 

    gameScene.attachChild(XOsprite); 
    gameScene.registerTouchArea(XOsprite); 

    return gameScene; 
} 

精靈剛剛淡出,什麼也沒有發生。我還希望精靈在淡入時變爲隨機位置。幫助?

回答

0

如果你想要淡入和平行縮放,那麼你可以使用parallelEntityModifier。

類似地,淡出和平行縮放然後你可以使用使用parallelEntityModifier。

要按順序運行這兩個,請使用SequenceEntityModifier。 試試這個會有用。