java - Zero KeyFrame animation generated by factory, works on direct instantiation -
java - Zero KeyFrame animation generated by factory, works on direct instantiation -
class define , contain libgdx animation:
public class screenobject { protected int width; protected int height; protected float statetime; protected string spritesheetfile; protected int spritesheetcols; protected int spritesheetrows; protected float frameduration; protected texture spritesheet; protected textureregion[] frames; protected animation animation; public void makeanimation() { spritesheet = new texture(spritesheetfile); textureregion[][] temp = textureregion.split(spritesheet, width, height); frames = new textureregion[spritesheetrows * spritesheetcols]; int index = 0; ( int = 0; < spritesheetrows; i++ ) { ( int j = 0; j < spritesheetcols; j++ ) { frames[index++] = temp[i][j]; } } animation = new animation(frameduration, frames); statetime = 0; } public void draw(spritebatch batch) { textureregion currentframe = animation.getkeyframe(statetime, true); batch.draw(currentframe, 0, 0); } }
if create class abstract , extend testscreenobject, can set attributes in constructor phone call makeanimation() , works expect.
if utilize mill class dynamically sets attribute values using setters , returns screenobject screenobject[] array, , phone call makeanimation() on screenobject referencing array index:
sof = new screenobjectfactory(); planets = new planet[] { sof.randomplanet() }; planets[0].makeanimation();
i partition 0 error on draw() call:
exception in thread "lwjgl application" java.lang.arithmeticexception: / 0 @ com.badlogic.gdx.graphics.g2d.animation.getkeyframeindex(animation.java:142)
the keyframes array animation has no frames in it! boggling tiny little mind. have verified screenobject generated mill , stored in screenobject[] array has had appropriate values set setters, , phone call same makeanimation() method uses values create animation... works 1 way , not other.
i've tried searching other issues arithmeticexception on getkeyframe(), , effect 2 different methods of creating screenobject class might have, i'm @ loss here.
java animation libgdx
Comments
Post a Comment