Button Slick2D GUI按钮侦听器
我试图通过扩展AbstractComponent使按钮变得光滑: 公共类StandardButton扩展了抽象组件{Button Slick2D GUI按钮侦听器,button,user-interface,slick2d,Button,User Interface,Slick2d,我试图通过扩展AbstractComponent使按钮变得光滑: 公共类StandardButton扩展了抽象组件{ 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 Heigh
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));
}
[...]
在我的州:
公共类UpdateState扩展BasicGameState实现ComponentListener{
私人标准按钮展示
@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方法不会运行。我该怎么做呢?我只想让我的程序在componentActivated方法中执行block。这是可能的,还是我只需要在update方法中的按钮字段中为所有按钮一直释放鼠标就可以了?我建议您快速执行在buckys视频上登峰造极,为您提供有关使用slick 2d制作东西的有用提示 这是他的教程播放列表的链接。其中一个视频讲述了如何制作按钮和切换状态。祝你好运,我希望你制作一个精彩的节目:)