这是两个问题:
1)对于使用代号的简单2D图形游戏,最好的方法paint
成员是否是Component
其中之一?还是我什至不应该尝试?
2)为什么下面的代码Component
只绘制my以便立即将其擦除?
我这样初始化我的组件:
protected void StartGame()
{
final Component newC = new PaintedComponent();
Container mv = findContainerMainVisual();
mv.addComponent(newC);
mv.setShouldCalcPreferredSize(true);
mv.animateLayout(200);
}
然后该组件将重写paint
成员函数,如下所示:
public class PaintedComponent extends Component {
private int nextColour;
public PaintedComponent() {
super();
setSize(new Dimension(200,200));
nextColour = 0x8f8f8f;
}
@Override
public void paint(Graphics g) {
super.paint(g); // I've tried without this, but it's the same
g.setColor(0xffffff);
g.fillRadialGradient(0xffffff, nextColour, 0,0,this.getWidth(), this.getHeight());
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句