Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to change directions of a sprite added to View AndEngine?
- 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);
- MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth());
- MoveYModifier mod = new MoveYModifier(actualDuration, target.getY(), - target.getHeight());
Add Comment
Please, Sign In to add comment