java - Issue with sounds in libgdx -
i having issues libgdx sound inside clicklistener
button. getting error syntax error on token "playbuttonsound", identifier expected after token
soundmanager:
import utils.constants; import com.badlogic.gdx.gdx; import com.badlogic.gdx.audio.music; import com.badlogic.gdx.audio.sound; public class soundmanager { private static sound buttonsound = gdx.audio.newsound(constants.buttonsound); private static music song = gdx.audio.newmusic(constants.song); public static void playmusic() { song.setlooping(true); song.setvolume(0.2f); song.play(); } public static void playbuttonsound() { buttonsound.play(); } public void destryoaudio() { buttonsound.dispose(); song.dispose(); } }
and mainmenu:
public class mainmenu implements screen { private stage stage; private sprite sprite; private textureregion menubackgroundimg; private textureatlas menubutton; private skin skin; private bitmapfont font; private table table; private textbutton playbutton; @override public void show() { // set stage stage = new stage(); gdx.input.setinputprocessor(stage); soundmanager.playmusic(); // set menu baggrund menubackgroundimg = new textureregion(new texture(gdx.files.internal(constants.menubackgroundimg))); sprite = new sprite(menubackgroundimg); sprite.setsize(gdx.graphics.getwidth(), gdx.graphics.getheight()); // set menuknapper menubutton = new textureatlas(constants.menubutton); skin = new skin(menubutton); // set font font = new bitmapfont(constants.font, false); // set table table = new table(skin); table.setbounds(0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight()); // create button styling textbuttonstyle textbuttonstyle = new textbuttonstyle(); textbuttonstyle.up = skin.getdrawable("menubuttonup"); textbuttonstyle.down = skin.getdrawable("menubuttonpressed"); textbuttonstyle.pressedoffsetx = 1; textbuttonstyle.pressedoffsety = -1; textbuttonstyle.font = font; textbuttonstyle.fontcolor = color.black; // create buttons playbutton = new textbutton(constants.play, textbuttonstyle); playbutton.addlistener(new inputlistener() { soundmanager.playbuttonsound(); // error }); // button padding playbutton.pad(20, 100, 20, 100); // setting table table.add(playbutton).row(); // setting stage actor stage.addactor(table); } @override public void render(float delta) { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); // tegn baggrund stage.getbatch().begin(); sprite.draw(stage.getbatch()); stage.getbatch().end(); // tegn resten stage.act(delta); stage.draw(); }
...
@override public void dispose() { stage.dispose(); menubutton.dispose(); skin.dispose(); font.dispose(); } }
i can't grasp doing wrong , search error gives vague answers dosen't solves issue.
p.s. have imported soundmanager
left out due length of code snippet.
you need implement 1 of inputlistener
interface methods, touchdown(inputevent event, float x, float y, int pointer, int button)
.
check out api inputlistener
. lists methods , gives pretty example.
playbutton.addlistener(new inputlistener() { public boolean touchdown (inputevent event, float x, float y, int pointer, int button) { soundmanager.playbuttonsound(); return false; } });
Comments
Post a Comment