java - libgdx - Image setDrawable not working -


changing actor(image subclass) texture @ runtime doesn't work. texture argument of constructor call drawn. searched solution, nothing did work. last try looking code in image constructor, sets drawable und calls setsize().

circuitelement extends image

public class bulb extends circuitelement {     boolean on;     int x, y;      textureregion bulbon;     textureregion bulboff;      public bulb (int x, int y, int id, textureregion i) {         super(i);          on = false;         //this.x = x;         //this.y = y;         this.id = id;          textureatlas atlas = new textureatlas(gdx.files.internal("switch.pack"));         bulbon = atlas.findregion("bulbon");         bulboff = atlas.findregion("bulboff");         setwidth(bulbon.getregionwidth());         setheight(bulbon.getregionheight());         setbounds(0, 0, getwidth(), getheight());         debug();          this.addlistener(new clicklistener() {             public void clicked(inputevent event, float x, float y) {                 if (on) {                     on = false;                 } else {                     on = true;                 }                 system.out.println(on);             }         });     }      @override     public void draw (batch batch, float parentalpha) {         if (on) {             setdrawable(new spritedrawable(new sprite(bulbon)));             //setwidth(bulbon.getregionwidth());             //setheight(bulbon.getregionheight());             //setbounds(0, 0, getwidth(), getheight());             setsize(getprefwidth(), getprefheight());         } else {             setdrawable(new spritedrawable(new sprite(bulboff)));             //setwidth(bulboff.getregionwidth());             //setheight(bulboff.getregionheight());             //setbounds(0, 0, getwidth(), getheight());             setsize(getprefwidth(), getprefheight());         }     } } 

i had call super.draw() in own draw-method, after calling setdrawable , setsize.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -