java游戏制作培训_如何用java制作沙盒游戏(How to make a sandbox game with java)

I'm trying to make a game that simulates chemical reactions. The problem is, after about five dust particles, the game crashes. Here's the code that moves particles:

public class Element extends Thread {

long temperature;

double x;

double y;

double XVel;

double YVel = 5;

ImageView iv;

Duration dur;

TranslateTransition tt = new TranslateTransition();

@Override

public void run() {

while (true) {

move();// calls the movement method repeatedly

try {

Thread.sleep(10);

} catch (InterruptedException ex) {

Logger.getLogger(Element.class.getName()).log(Level.SEVERE, null, ex);

}

}

}

public void initialize() {

this.start();

}

/**

* @return the temperature

*/

public long getTemperature() {

return temperature;

}

public void checkCollisions() {

}

public void move() {

tt.setDuration(dur.millis(5));

tt.setByY(YVel);

tt.setCycleCount(1);

tt.setNode(iv);

tt.play();

}

}

Then, this exception comes up, and the game stops working:

java.lang.NullPointerException

at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:366)

at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:366)

at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:289)

at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)

at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:332)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)

at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)

at java.lang.Thread.run(Thread.java:744)

I don't know why a NullPointerException occurs, can anybody help me (I'm using JavaFX)? It would be very helpful if someone could tell me how this game does it (http://dan-ball.jp/en/javagame/dust/), for this game shows what i'm trying to accomplish. See for yourself.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值