java - Create an Array which contains a RECTANGLE and an INTEGER -
private array<rectangle> livinglamas;
i want array contain integer every rectangle. integer should specified in spawnlama() every rectangle contains own value. how do this?
private void spawnlama() { rectangle livinglama = new rectangle(); livinglama.x = mathutils.random(-800, -400 - 64); livinglama.y = 0; livinglama.width = 64; livinglama.height = 64; livinglamas.add(livinglama); lastlamatime = timeutils.nanotime(); }
and
@override public void render() {
...
elapsedtime += gdx.graphics.getdeltatime(); if(timeutils.nanotime() - lastlamatime > 1000000000l) spawnlama(); iterator<rectangle> iter = livinglamas.iterator(); while(iter.hasnext()) { rectangle livinglama = iter.next(); livinglama.x += lamaxbewegung * gdx.graphics.getdeltatime(); if(livinglama.y + 64 < -575) iter.remove(); } batch.begin(); for(rectangle livinglama: livinglamas) { batch.draw(animation.getkeyframe(elapsedtime, true), livinglama.x, livinglama.y); } elapsedtime += gdx.graphics.getdeltatime();
...
subclass , use subclass instead of rectangle:
public class rectanglewithint extends rectangle { public int value; }
or use libgdx's arraymap. unlike java's map, can have duplicate keys, , array, ordered:
private arraymap<rectangle, integer> livinglamas; //... livinglamas.put(livinglama, someint); //... iterator<entry<rectangle, integer>> iter = livinglamas.iterator(); while (iter.hasnext()){ entry<rectangle, integer> entry = iter.next(); rectangle lama = entry.key; int value = entry.value; //... }
Comments
Post a Comment