java - Why doesnt my program draw the houses from the arrayList? -



java - Why doesnt my program draw the houses from the arrayList? -

i want in game draw houses (huis = house) fall continuesly @ sides of screen. (on grass 'world' moves downwards.'

but,having code, , no problem in logcat dont know why doesnt draw houses. 'main flow' of code goes follows: created arraylist holds house.png. through loop adds house when there space between it.

package com.mygdx.papermadness; import java.util.arraylist; import com.badlogic.gdx.applicationlistener; import com.badlogic.gdx.gdx; import com.badlogic.gdx.inputadapter; import com.badlogic.gdx.audio.music; import com.badlogic.gdx.graphics.color; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.texture.texturewrap; import com.badlogic.gdx.graphics.g2d.sprite; import com.badlogic.gdx.graphics.g2d.spritebatch; import com.badlogic.gdx.graphics.glutils.shaperenderer; import com.badlogic.gdx.graphics.glutils.shaperenderer.shapetype; import com.badlogic.gdx.math.rectangle; import com.badlogic.gdx.math.vector2; public class papermadness extends inputadapter implements applicationlistener { private spritebatch huisbatch; private texture huistexture; private spritebatch batch; private sprite sprite; private spritebatch spritebatch; private sprite huissprite; private texture spritetexture; private float scrolltimer = 0.0f; private float huisvelocity = 200f; private float huislinksy = 2100; private float huislinksx = 0; private float huisrechtsy = 2100; private float huisrechtsx = 903; private sprite huis; private arraylist<sprite> huisarray = new arraylist<sprite>(); rectangle bounds; player player; paper paper; shaperenderer sr; @override public void create() { player = new player(new vector2(50, 100), new vector2(100, 100)); paper = new paper(new vector2(gdx.input.getx(),gdx.graphics.getheight()-gdx.input.gety()), new vector2(50, 50)); sr = new shaperenderer(); spritebatch = new spritebatch(); huisbatch = new spritebatch(); huistexture = new texture("huis.png"); huissprite = new sprite(huistexture); spritetexture = new texture("b2.png"); spritetexture.setwrap(texturewrap.repeat, texturewrap.repeat); sprite = new sprite(spritetexture); sprite.setsize(gdx.graphics.getwidth(), gdx.graphics.getheight()); batch = new spritebatch(); } @override public void render() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); float delta = gdx.graphics.getdeltatime(); scrolltimer += gdx.graphics.getdeltatime(); if (scrolltimer > 2f) scrolltimer = 0.0f; sprite.setv(scrolltimer + 2); sprite.setv2(scrolltimer); player.update(); paper.update(); spritebatch.begin(); sprite.draw(spritebatch); (int = 0; < huisarray.size(); i++) { huisarray.get(i).sety(huisarray.get(i).gety() - huisvelocity * delta); if (huisarray.get(i).gety() <= 200) { huisarray.remove(i); i--; } } if (huisarray.size() > 0 && huisarray.get(0).gety() < 1200) { addnewhuis(); } huisbatch.begin(); (int = 0; < huisarray.size(); i++) { huisbatch.draw(huisarray.get(i), huisarray.get(i).getx(), huisarray.get(i).gety()); } huislinksy -= huisvelocity * delta; huisrechtsy -= huisvelocity * delta; batch.begin(); player.draw(batch); paper.draw(batch); batch.end(); sr.begin(shapetype.filled); sr.setcolor(color.blue); sr.setcolor(color.red); sr.setcolor(color.yellow); sr.rect(gdx.input.getx(), gdx.graphics.getheight() - gdx.input.gety(), paper.getsize().x, paper.getsize().y); sr.end(); } private void addnewhuis() { huis = new sprite(); huis.sety(1800); huisarray.add(0, huis); } @override public void resize(int width, int height) { // todo auto-generated method stub } @override public void pause() { // todo auto-generated method stub } @override public void resume() { // todo auto-generated method stub } @override public void dispose() { // todo auto-generated method stub } }

any help appreciated.

from point of view, house array empty - not have draw. create huisarray, not add together it. when render() called first, huisarray.size() == 0 true.

for (int = 0; < huisarray.size(); i++) { //you not step piece of code. huisarray.get(i).sety(huisarray.get(i).gety() - huisvelocity * delta); if (huisarray.get(i).gety() <= 200) { huisarray.remove(i); i--; } }

then, want add together house if there houses there. it's still empty not add together anything.

if (huisarray.size() > 0 && huisarray.get(0).gety() < 1200) { addnewhuis(); }

and effort draw still empty array:

huisbatch.begin(); (int = 0; < huisarray.size(); i++) { //you not step piece of code either huisbatch.draw(huisarray.get(i), huisarray.get(i).getx(), huisarray.get(i).gety()); }

solution: add together one-two huissprite huisarray in create().

hope helps :)

java android arraylist libgdx

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -