Guest User

Untitled

a guest
Aug 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. How to change directions of a sprite added to View AndEngine?
  2. public void addTarget(){
  3. /*
  4. * We are determining the minimum and maximum y position for the targets to appear at then
  5. * use the Random() class to generate a random number so the value of y is
  6. * still on the screen while the x value replaces the sprite just before the right side or the screen.
  7. *
  8. */
  9. Random rand = new Random();
  10.  
  11. int x = (int) mCamera.getWidth() + mTargetTextureRegion.getWidth();
  12. int minY = mTargetTextureRegion.getHeight();
  13. int maxY = (int)(mCamera.getHeight() - mTargetTextureRegion.getHeight());
  14. int rangeY = maxY - minY;
  15. int y = rand.nextInt(rangeY) + minY;
  16.  
  17. Sprite target = new Sprite(x,y,mTargetTextureRegion.clone());
  18. SceneMainScene.attachChild(target);
  19.  
  20. int minDuration = 2;
  21. int maxDuration = 4;
  22.  
  23. int rangeDuration = maxDuration - minDuration;
  24. int actualDuration = rand.nextInt(rangeDuration) + minDuration;
  25.  
  26. MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth());
  27.  
  28. target.registerEntityModifier(mod);
  29. TargetsToBeAdded.add(target);
  30.  
  31. MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth());
  32.  
  33. MoveYModifier mod = new MoveYModifier(actualDuration, target.getY(), - target.getHeight());
Add Comment
Please, Sign In to add comment