Libgdx Array<> How To Get Last Item?
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
Solution 1:
You should try this,
if(cam.position.y > buckets.peek().getPosition().y){
for(Bucket bucket : buckets){
bucket.repos(rand.nextInt((int)W)/PPM,buckets.size+BUCKET_MARGIN/PPM);
}
}
In this y position of buckets are not properly specified because according to your code all bucket set to particular y position.
EDIT
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);
}
}
EDIT 2
Take a look of this tutorial, I think it may be helpful for you.
Post a Comment for "Libgdx Array<> How To Get Last Item?"