Slick2D GUI按钮侦听 [英] Slick2D GUI Button listener
问题描述
我试图通过扩大AbstractComponent使在光滑的按钮:
I'm trying to make button in slick by extending AbstractComponent:
公共类StandardButton扩展AbstractComponent {
public class StandardButton extends AbstractComponent {
protected int x;
protected int y;
protected int Width;
protected int Height;
protected String Text;
public StandardButton(GUIContext container,int x, int y, String Text, int Width, int Height,ComponentListener listener) {
super(container);
this.Text=Text;
setLocation(x, y);
this.Width=Width;
this.Height=Height;
addListener(listener);
}
@Override
public void render(GUIContext container, Graphics g) throws SlickException {
g.setColor(Color.white);
g.setLineWidth(2f);
g.drawRect(x, y, Width, Height);
g.drawString(Text, x+5, y+(Height/2-4));
}
[...]
在我的状态:
公共类UpdaterState扩展BasicGameState实现的ComponentListener {
私人StandardButton buttonPlay;
public class UpdaterState extends BasicGameState implements ComponentListener { private StandardButton buttonPlay;
@Override
public void init(GameContainer container, final StateBasedGame game)
throws SlickException {
buttonPlay=new StandardButton(container,100,100,"Graj",60,30,new ComponentListener(){
@Override
public void componentActivated(AbstractComponent source) {
State.nextState(0, game);
}
});
但没有任何反应。当我点击我的按钮,我nestState方法不运行。我怎么schould这样做是否正确?我只是想我的程序做块componentActivated方法。那是可能的,或者我只需要chceck如果释放鼠标在我的按钮场更新方法所有的时间对所有的按钮?
But nothing happens. My nestState method does not run when i click my button. How schould I do that correctly? I just want my program to do block in componentActivated method. Is that possible or i just need to chceck if mouse is released on my button field in update method all the time for all buttons?
推荐答案
我会建议你在胸片架,其中的视频给你做的东西用油滑2D有用的提示采取快速峰值。
I would recommend you take a quick peak at buckys videos which give you helpful tips on making stuff with slick 2d.
的http://www.youtube.com/watch?v=AXNDBQfCd08&feature=share&list=PL22EF3E3752768216
这就是他的教程的播放列表的链接。其中一个视频谈论制作按钮和开关状态。祝你好运,我希望你做一个惊人的计划:)
That's a link to the playlist of his tutorials. One of the videos talks about making buttons and switching states. Good luck and I hope you make an amazing program :)
这篇关于Slick2D GUI按钮侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!