我是游戏开发的新手。我使用and-engine 来开发游戏。我从屏幕顶部使用下面的代码随机创建像物体坠落的场景。
TimerHandler spriteTimerHandler;
float mEffectSpawnDelay = 3f;
spriteTimerHandler = new TimerHandler(mEffectSpawnDelay, true,
new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
Random rand = new Random();
int y = (int) (resourcesManager.camera.getHeight() + resourcesManager.ball2.getHeight());
int minx = (int) (resourcesManager.ball1.getHeight());
int maxx = (int) (resourcesManager.camera.getWidth() - resourcesManager.ball2.getWidth());
int rangex = maxx- minx;
int x = rand.nextInt(rangex) + minx;
Sprite target = new Sprite(x, y, resourcesManager.ball2.deepCopy(),vbom);
attachChild(target);
int minDuration = 4;
int maxDuration = 8;
int rangeDuration = maxDuration - minDuration;
int actualDuration = rand.nextInt(rangeDuration) + minDuration;
MoveYModifier mod = new MoveYModifier(actualDuration, target.getY(),-target.getHeight());
target.registerEntityModifier(mod.deepCopy());
TargetsToBeAdded.add(target);
}
});
registerUpdateHandler(spriteTimerHandler);
从这段代码中,对象来自屏幕顶部,但它遍布整个宽度。我想将对象从屏幕的一半设置到屏幕的末尾。有人知道请帮我解决这个问题问题。