Reputation: 26971
I am using AndEngine.
I have a Method that adds targets to the screne.
Here is my method..
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);
It works fine. The only problem i am having is that the Targets come onto the screen from left to right.. I would like to change this so the Targets are displayed from top to bottom?
I cant figure out in my code what i need to change to do this? Any suggestions?
Upvotes: 1
Views: 649
Reputation: 3063
You are using a
MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(), - target.getWidth());
try using a
MoveYModifier mod = new MoveYModifier(actualDuration, target.getY(), - target.getHeight());
In AndEngine (0,0) is the top left corner, X increase going to the right and Y increase going down
Upvotes: 3