2011-11-03 96 views
1

我正在使用AndEngine。如何更改添加到View AndEngine中的精灵的方向?

我有一个方法,将目标添加到screne。

这里是我的方法..

public void addTarget(){ 
    /* 
    * We are determining the minimum and maximum y position for the targets to appear at then 
    * use the Random() class to generate a random number so the value of y is 
    * still on the screen while the x value replaces the sprite just before the right side or the screen. 
    * 
    */ 
    Random rand = new Random(); 

    int x = (int) mCamera.getWidth() + mTargetTextureRegion.getWidth(); 
    int minY = mTargetTextureRegion.getHeight(); 
    int maxY = (int)(mCamera.getHeight() - mTargetTextureRegion.getHeight()); 
    int rangeY = maxY - minY; 
    int y = rand.nextInt(rangeY) + minY; 

    Sprite target = new Sprite(x,y,mTargetTextureRegion.clone()); 
    SceneMainScene.attachChild(target); 

    int minDuration = 2; 
    int maxDuration = 4; 

    int rangeDuration = maxDuration - minDuration; 
    int actualDuration = rand.nextInt(rangeDuration) + minDuration; 

    MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth()); 

    target.registerEntityModifier(mod); 
    TargetsToBeAdded.add(target); 

它工作正常。我遇到的唯一问题是目标从左到右进入屏幕..我想改变这个,所以目标从上到下显示?

我不能在我的代码中找出我需要改变的地方吗?有什么建议么?

回答

3

您正在使用使用

MoveYModifier mod = new MoveYModifier(actualDuration, target.getY(), - target.getHeight()); 

在AndEngine(0,0)一

MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth()); 

尝试的左上角,X增幅将下降

权和Y增加
+0

当我更换代码没有任何反应。精灵不会出现在屏幕上。当我把它切换回原来的工作。还有其他建议吗? –

+1

精灵可能不会显示,因为它在屏幕之外创建并移出屏幕。尝试从你确定存在于窗口内的值中加入e,以检查运动是否正确。如果是这样,那么改变2点,记住一个引擎的坐标系 –

+0

你可以在答案中张贴? –