Java string returning null after definition -
as title says, i'm using java , having problems string returning null @ runtime though set previously. i'm using libgdx doesn't complicate @ point, seemingly simple. or i'm tired.
here's code:
package com.jett.game; import java.util.arraylist; import com.badlogic.gdx.gdx; import com.badlogic.gdx.input.keys; import com.badlogic.gdx.screen; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.orthographiccamera; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.g2d.bitmapfont; import com.badlogic.gdx.graphics.g2d.sprite; import com.badlogic.gdx.graphics.g2d.spritebatch; import com.badlogic.gdx.graphics.g2d.freetype.freetypefontgenerator; import com.badlogic.gdx.graphics.g2d.freetype.freetypefontgenerator.freetypefontparameter; import com.badlogic.gdx.utils.array; public class gamescreen implements screen{ public orthographiccamera cam; public player player; public spritebatch mainbatch; public array<sprite> firesprites; public sprite bartablesprite; public texture choicebanner; public texture blackboardtex; public boolean paymentchoice; public freetypefontgenerator fontgenerator; public freetypefontparameter fontparameter; public bitmapfont font; public int shopmoney = 3000; public float daytime; public float firespriteindex; public customer customer; public arraylist<favor> favors; // there should 3 favors @ once. wont break otherwise, become difficult public gamescreen(){ favors = new arraylist<favor>(); favors.add(new favor(1,"get 50 logs of wood.")); favors.add(new favor(2, "find hammer")); blackboardtex = new texture(gdx.files.internal("blackboard.png")); fontgenerator = new freetypefontgenerator(gdx.files.internal("coolville.ttf")); fontparameter = new freetypefontparameter(); fontparameter.size = 9; font = fontgenerator.generatefont(fontparameter); mainbatch = new spritebatch(); player = new player(-50,0); cam = new orthographiccamera(16*10,9*10); player.batcher.setprojectionmatrix(cam.combined); choicebanner = new texture(gdx.files.internal("choicebanner.png")); bartablesprite = new sprite(new texture(gdx.files.internal("bartable.png"))); firesprites = new array<sprite>(); firesprites.add(new sprite(new texture(gdx.files.internal("fire1.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire2.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire3.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire4.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire5.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire6.png")))); firesprites.add(new sprite(new texture(gdx.files.internal("fire7.png")))); mainbatch.setprojectionmatrix(cam.combined); customer = new dwarfscythe(80, 0); customer.batcher.setprojectionmatrix(cam.combined); } @override public void render(float delta) { gdx.app.log("blackboard favors: ", ""+favors.size()); if(customer != null){ if(customer.current_state == customer.talking){ paymentchoice = true; } customer.delta = delta; if(customer.haspayed){ paymentchoice = false; customer = null; } } gdx.graphics.getgl20().glclear(gl20.gl_color_buffer_bit); gdx.graphics.getgl20().glclearcolor(0.05f, 0.05f, 0.05f, 1); player.render(); player.logic(delta); firespriteindex += delta*5; mainbatch.begin(); // background mainbatch.draw(bartablesprite, -48, 0); mainbatch.draw(firesprites.get((int)firespriteindex), 0, 0); mainbatch.end(); // people if(customer != null){ customer.render(); customer.logic(); } // ui mainbatch.begin(); mainbatch.draw(blackboardtex, -blackboardtex.getwidth()/2, -blackboardtex.getheight()/2); gdx.app.log("favor 1 name: ",favors.get(1).name); // returns: favor 1 name: null //font.draw(mainbatch, favors.get(1).name, -blackboardtex.getwidth()/2+5, blackboardtex.getheight()/2-5); font.draw(mainbatch, "gold: " + shopmoney, -80, 44); if(paymentchoice){ mainbatch.draw(choicebanner, -16,-16); if(gdx.input.iskeyjustpressed(keys.g)){ // gold if(customer.ischeap){ shopmoney += customer.money/4; } else{ shopmoney += customer.money; } customer.haspayed = true; } if(gdx.input.iskeyjustpressed(keys.h)){ // } } mainbatch.end(); if(firespriteindex >= 6.5f){ firespriteindex = 0; } } @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 hide() { // todo auto-generated method stub } @override public void dispose() { // todo auto-generated method stub } @override public void show() { // todo auto-generated method stub } }
the problem has been fixed. appears have made error during development of favor class. sorry become subjective, noticed over-complicating adding these classes, when could've added arraylist of strings. that's did, , problem solved.
Comments
Post a Comment