当相机的Y位置高于上次创建的存储桶"时,我想更改存储桶"的Y位置Y位置:"create()"方法中有我的代码
I want to change Y position of "bucket", when camera Y position is higher than "last created bucket" Y position: There is my code in "create()" method
buckets = new Array<Bucket>(); for(int i=1;i<BUCKET_COUNT;i++){ buckets.add(new Bucket(world,(rand.nextInt((int)W)-45)/PPM,BUCKET_MARGIN*i/PPM)); }我正在"render()"方法中这样做:
And I am doing like this in "render()" method:
for(Bucket bucket : buckets){ if(cam.position.y > buckets.peek().getBody().getPosition().y){ bucket.repos(rand.nextInt((int)W)/PPM,buckets.size+BUCKET_MARGIN/PPM); } }repos():
public void repos(float x, float y){ setPosition(x, y);//Bucket class is extends Sprite }但是它不起作用,我也不知道如何解决这个问题
But it doesn't work and I don't know how to solve this problem
我想知道如何从那些数组中获得 last 个项目?
I want to know how to get last item from those array?
推荐答案您应该尝试一下
if(cam.position.y > buckets.peek().getPosition().y){ for(Bucket bucket : buckets){ bucket.repos(rand.nextInt((int)W)/PPM,buckets.size+BUCKET_MARGIN/PPM); } }在此y位置中,未正确指定存储桶,因为根据您的代码,所有存储桶都设置为特定的y位置.
In this y position of buckets are not properly specified because according to your code all bucket set to particular y position.
编辑
if(cam.position.y > buckets.peek().getPosition().y){ for(Bucket bucket : buckets){ bucket.repos(rand.nextInt((int)W)/PPM,cam.position.y+bucket.getPositon().y); } }编辑2
看看这个教程,我认为这可能对您有所帮助.
Take a look of this tutorial, I think it may be helpful for you.
更多推荐
Libgdx阵列如何获得最后一个项目?
发布评论