java - Setting text on Label (Actor) stops drawing -
i can't figure this, , pulling hair out right now!!
i have stage
label
added it, set , first time call stage.draw()
works fine. however, set text of label
nothing gets drawn. funny thing is, when don't change text draws expected, when call label.settext("the text")
doesn't draw.
i have stepped through code , have noted down height
, width
, x
, y
values before , after setting text of label
, , same (before , after).
also, when draw stage
it's drawn above sprite
, , positioning sprite
based on label
's position. sprite
draws fine before set text on label
, after.
ps: have made sure sprite
not drawn "over" label
.
this setup:
i have maingame
class renders player
class, when ever back
button pressed sprite
stage
gets drawn, or should drawn.
spritebatch.begin(); player.update(spritebatch, delta); spritebatch.end(); // pause menu drawn separate sprite batch needs in middle relative screen , above else if (player.ispaused()){ messagespritebatch.begin(); messagesprite.draw(messagespritebatch); messagespritebatch.end(); messagestage.draw(); // stage doesn't seem getting drawn }
player class - update method
if (!paused){ // removed clarity }else{ // on maingame class render small box 1 of following messages // ready // pause // quit? // game on if (gdx.input.justtouched()){ paused = false; } spritebatch.setprojectionmatrix(camera.combined); camera.update(); } messagespritebatch = new spritebatch(); messagestage = new stage(gdx.graphics.getwidth(), gdx.graphics.getheight()); messagefont = new bitmapfont(gdx.files.internal("fonts/fontfile.fnt")); messagestyle = new labelstyle(); messagestyle.font = messagefont; messagelabel = new label("ready", messagestyle);
this how initialise label
, sprite
, stage
:
float fontscalex = gdx.graphics.getwidth()/scale_x_divider; float fontscaley = gdx.graphics.getheight()/scale_y_divider; messagelabel.setfontscale(fontscalex*1.4f, fontscaley*4.2f); messagelabel.setposition((messagestage.getwidth()/2)-((messagelabel.getwidth()/2)*messagelabel.getfontscalex()), (messagestage.getheight()/2)-((messagelabel.getheight()/2)*messagelabel.getfontscaley())+(player.getscoreboard().getsize().y/2)); messagestage.addactor(messagelabel); messagestage.act(); messagetexture = new texture(gdx.files.internal("images/message_background.png")); messagesprite = new sprite(messagetexture); messagesprite.setsize((messagelabel.getwidth()*messagelabel.getfontscalex())*1.5f, (messagelabel.getheight()*messagelabel.getfontscaley())*3); messagesprite.setposition(messagelabel.getx()-(messagesprite.getwidth()/6), messagelabel.gety()-messagesprite.getheight()/2);
please me, before bald xd
well width , height of label set once when creating label, matching width , height of initial text passed constructor. of course can make bigger setting width , height later on. use alignments way...
are using special characters when changing text, font has problem that?
maybe posting code give more insights...
Comments
Post a Comment