Libgdx阵列如何获得最后一个项目?

编程入门 行业动态 更新时间:2024-10-08 12:43:12
本文介绍了Libgdx阵列如何获得最后一个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当相机的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阵列如何获得最后一个项目?

本文发布于:2023-11-13 03:04:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列   如何获得   项目   Libgdx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!