手机游戏<搜神引擎帐>那个引擎怎么用

天极传媒:天极网全国分站
您现在的位置: &&
J2ME手机游戏引擎程序结构简述
J2ME开发网 14:53
  游戏引擎的结构很多,不过基本上都是在一个游戏主循环内实现。程序里面的主循环包含了程序框架的最主要的结构体。J2me的程序一般都包含两个class文件,一个是MIDlet,一个是Displayable。一般我都是把游戏的主要代码放在Displayable这个类里面。这个类是基于事件驱动的程序,有三个主要相应函数void paint(Graphics g),void keyPressed(int keyCode),void keyReleased(int keyCode)。  1.使用Runnable和创建线程的主循环  一般主体的做法就是让Displayable这个类实现Runnable这个接口,然后在其构造函数中创建一个线程,启动其run()函数,而run函数里面就包含了游戏的主循环。下面是我在仙剑里面的片断代码。
public class GameMIDlet extends MIDlet {static GameMIDDGameDisplayable displayable =public GameMIDlet() {instance =display = Display.getDisplay(this);displayable = new GameDisplayable();}public void startApp() {display.setCurrent(displayable);}public void pauseApp() {}public void destroyApp(boolean unconditional) {displayable.running =}public static void quitApp() {instance.destroyApp(true);instance.notifyDestroyed();instance =}}public class GameDisplayable extends FullCanvas implements Runnable {/** 主控制线程 */Thread MainThread =/** 游戏时钟间隔 毫秒为单位 */public static long timeinterval = 20;public static boolean Isstable =/* 用于游戏时钟的变量 */public static long timeold = 0;public static long timenow = 0;public long interval = 0;public static long frames_per_second = 0;int count = 0;long second = 0;public static boolean running = public GameDisplayable() {// 开始主线程Thread MainThread = new Thread(this);MainThread.start();}public void run() {while (running) {timenow = System.currentTimeMillis();interval = timenow -if (interval &= timeinterval) {timeold =Game_Process();if (second != (System.currentTimeMillis() / 1000)) {second = System.currentTimeMillis() / 1000;frames_per_second =count = 1;}elsecount++;}lib.sleep(30);}}  其中关于控制主循环速度的代码可以不要,但是lib.sleep(30)必须保留,因为在Nokia 60的上,如果去除了sleep(30),那么游戏将无法切换回来。同时,在游戏中任何一个内部循环中,也必须加入sleep(30)这个等待,才能让游戏可以切换回来,至于为什么这样做,我暂时还不清楚。30ms是我过没有问题的数值,可能比30ms还小的值也是没有问题的。  同时,在MOTO的手机上,必须将游戏的主循环放在一个线程中,游戏才能切换回来,不过可以不加上面说的sleep(30)延时。  2.不使用线程的主循环办法  这个办法只能在Nokia的平台上实现,而我只建议在Nokia 40的平台上做,这样不需要线程,道理上来说节约了一些,如果不是内存很紧张的机型,那么最好还是使用上一种办法。  游戏的主循环放在MIDlet的class里面,具体做法如下:
public class GameMIDlet extends MIDlet {GameDisplayable displayable =/** 游戏时钟间隔 毫秒为单位 */public static long timeinterval = 0;//用于游戏时钟的变量public static long timeold = 0;public static long timenow = 0;public long interval = 0;public static long frames_per_second=0;int count=0;long second =0;public static boolean running =static boolean exitApp =public GameMIDlet() {displayable = new GameDisplayable();running =}public void startApp() {running =Display.getDisplay(this).setCurrent(displayable);while(running) {timenow = System.currentTimeMillis();interval = timenow -if (interval &= timeinterval) {timeold =displayable.Game_Process();if(second != (System.currentTimeMillis() /1000)){second = System.currentTimeMillis()/1000;frames_per_second =count = 1;}elsecount ++;}}if(exitApp) {destroyApp(true);notifyDestroyed();}}public void pauseApp() {running =}public void destroyApp(boolean unconditional) {running =}public static void quitApp() {running =exitApp =}}
(作者:唐良责任编辑:方舟)
欢迎在新浪微博上关注我们
笔记本手机数码家电今日论坛第 1 个签到,每日签到可得财富值+2,连续5天签到后再连续签到则每日可得财富值
+4,记得每天都来签到哦~
上一主题:
下一主题:
查看: 14800 | 回复: 72
最新XX游戏《搜神帐》搜神类RPG,《抗日英雄》-爱国RPG
UID 7862772
财富值 1420
交易信用 0
积分/帖子:810
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
最新XX游戏《搜神帐》搜神类RPG,《抗日英雄》-爱国RPG
创新搜神类RPG,齐天大圣,魔神蚩尤,妖妇妲己等60个三界英灵猛将等你搜集,为你独尊!漫画战斗风格开创RPG战斗先河!各种恶搞对白角色打开游戏1分钟就能看到!
PS:没那么多新游戏,弄不了一更,就先把最新的给大家玩吧~~提前国庆快乐
有人早发了,所以在4L更新了个新游戏抗日英雄-爱国RPG
[ 本帖最后由 whl1994328 于
19:16 编辑 ]
&&下载次数: 1330
(1020.23 KB)
(34.79 KB)
评分次数:1 次 &财富值: +4 &&&&
绅士无非就是有耐心的狼screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
财富值 163
交易信用 0
积分/帖子:141
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
貌似已经有人发过了~
UID 7862772
财富值 1420
交易信用 0
积分/帖子:810
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
郁闷,突然发现有人发过了,那就再发几个新游戏就是了
绅士无非就是有耐心的狼screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
UID 7862772
财富值 1420
交易信用 0
积分/帖子:810
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
抗日英雄-爱国RPG
60年建国普天同庆,爱国手游不可不玩!你将扮演一位少年英雄,在紧张激烈,环环相扣的剧情中体验那段无法忘怀的激情岁月。刺激的剧情,休闲的小游戏,更有独特的荣誉勋章系统,为了至高无上的荣誉,努力奋斗吧!
[ 本帖最后由 whl1994328 于
19:16 编辑 ]
(20.24 KB)
&&下载次数: 345
(698.71 KB)
绅士无非就是有耐心的狼screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
交易信用 0
积分/帖子:77
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
虽然没下,还是感谢分享
(game over)
UID 1733225
财富值 40374
好评度 100
交易信用 0
荣誉卸任管理组
积分/帖子:10094
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
iphone 3GS
来自:Heart
状态: 离线
很不错的说
screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
横跨道德宇宙的弧线是漫长的,但它偏向正义!闪耀吧赞美诗
(安可思丢丢)
UID 8056973
财富值 4933
贡献值 3293
交易信用 0
荣誉卸任特殊组
积分/帖子:3902
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
来自:未知
状态: 离线
感谢分享了
screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
UID 5746914
财富值 128
交易信用 0
积分/帖子:162
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
抗日英雄-爱国RPG
我下的是这个 不过好像支线任务的任务道具怎么打都是1,没有办法完成任务...[s:22]
UID 7862772
财富值 1420
交易信用 0
积分/帖子:810
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
回复 #8 mmini 的帖子
......没测试那么多,你搜索下攻略吧或者不用做支线
绅士无非就是有耐心的狼screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized= this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" />
UID 2257079
财富值 179
交易信用 0
积分/帖子:325
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
感谢分享了
UID 5545553
财富值 204
交易信用 0
积分/帖子:259
连续签到天数:1
全部签到天数:15
注册时间:
手机型号:
状态: 离线
顶一下下!!~~~
UID 7449020
财富值 181
交易信用 0
积分/帖子:176
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
[s:27] 支持爱国手游!!!!
交易信用 0
积分/帖子:9
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
谢谢分享..
UID 7824760
财富值 192
交易信用 0
积分/帖子:193
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
[s:23] [s:23] [s:23]
UID 6729290
财富值 109
交易信用 0
积分/帖子:113
连续签到天数:0
全部签到天数:0
注册时间:
手机型号:
状态: 离线
支持LZ&&继续加油啊[s:23]
微信扫一扫关注dospy

参考资料

 

随机推荐