您的位置:首页 > 其它

个位大虾帮忙看一下,小弟实在太菜了,在此谢过~~~~~~~~

2017-01-03 05:29 295 查看
我要编一个坦克大战游戏,现以将坦克的功能和子弹的功能编好,但不能解决线程的同步问题,请个位大虾帮帮忙

代码如下(部分省略)

public class TankSprite extends GameCanvas implements Runnable{

public TankSprite() {

super(true);

try {

Tanksprite();

} catch (IOException e) {

e.printStackTrace();



tankmap = new TankMap();

start();

}

public void start(){

isRun = true;

Thread t = new Thread(this);

t.start();

}

public void stop(){

isRun = false;

}

public void run() {

mSprite.setFrame(0);

while(isRun == true){

render(g);

input();

try{

Thread.sleep(mFrameDelay);

}catch(InterruptedException ie){}

}

}

}

public class BulletSprite extends TankSprite implements Runnable{

public BulletSprite() {

try {

bulletSprite();

} catch (IOException e) {

e.printStackTrace();



start();

}

public void bulletSprite() throws IOException {

bullet = Image.createImage("/bullet.png");

mSprite = new Sprite(bullet);

flushGraphics();

}

public void start(){

isRun = true;

Thread t = new Thread(this);

t.start();

}

public void stop(){

isRun = false;

}

public void run() {

mSprite.setFrame(0);

while(isRun == true){

tankmap.mBackground.paint(g);

mSprite.setPosition(x, y);

fire();

try{

Thread.sleep(mFrameDelay);

}catch(InterruptedException ie){}

}

}

}

我就是想将两个类中的rum()方法同时执行,互不影响

如能答复,小弟感激不尽
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐