个位大虾帮忙看一下,小弟实在太菜了,在此谢过~~~~~~~~
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()方法同时执行,互不影响
如能答复,小弟感激不尽
代码如下(部分省略)
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()方法同时执行,互不影响
如能答复,小弟感激不尽
相关文章推荐
- 各位高手帮忙看一下我的电脑配置单,请大虾多提建议,小弟不胜感激!
- 求大虾帮忙!javabean的使用问题 ,小弟再次先谢过了
- 实验,求高手帮忙做下,小弟在此谢过了啊,大侠帮忙的来啊
- 请求帮忙,在此先谢过~~
- 小弟正式开博,请个位大虾指教~
- 小弟迷茫中,大虾帮忙!
- 矩阵运算的GPU加速!!求教各位大神帮忙!在此谢过
- 各位大虾,帮忙看一下呀,我的这个有没有错保存不了??第二面附上请求的ASP代码
- 7月20日Java基础:本人为新手正在学习Java中把每天学的东西晚上都会在博客记录希望大神可以指点 不足在此谢过。
- 谁能帮忙看一下,这个程序错误到底出在哪里?
- delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢
- 7月21日Objiect的常用类本人为新手正在学习Java中把每天学的东西晚上都会在博客记录希望大神可以指点 不足在此谢过。
- 各位帮忙看一下这个求100!的小程序哪里错啦?
- 帮忙看一下这个程序,为什么在调式时候调不出来
- 请求高手解决此拓扑,在此小弟万分感谢!
- delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢
- 做过http异步下载文件的请帮忙看一下
- 我是新手,大家帮忙看看这个问题怎样解决,小弟先谢啦
- MyEclipse+Tomcat 问题 麻烦各位帮忙看一下
- delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢