学习HTML5开发RPG游戏第三步>基本对象设计<四>
2013-12-18 17:14
483 查看
7、对话框
用于显示信息。
8、声音
这里写的比较简单。
9、时钟
时钟只有一个,所有的动画和移动,都是由它来驱动的。
至此,基本对象已经设计完成,下篇开始就要设计游戏中的具体对象了。
用于显示信息。
JControls.MessageBox = Class.create(JControls.Object, { initialize:function ($super, argname, argWH, argAString,argP) { //如果没有指定显示位置,则居中显示 if(!argP)argP={x:parseInt((JForm.size.width - argWH.width) / 2), y:parseInt((JForm.size.height - argWH.height) / 2)}; $super(argname,argP, argWH); this.BGColor = JColor.white; JForm.addControlInLast([this]);//把消息框添加到主窗体内 var messageTitle = new JControls.Label(argname + "lbT", {x:0, y:0}, "系统提示"); messageTitle.BGColor = JColor.blue; messageTitle.fontColor = JColor.red; messageTitle.size.width = argWH.width; messageTitle.size.height = 25; messageTitle.fontSize = 20; messageTitle.fontType = "bold"; this.addControlInLast([messageTitle]);//添加消息标题栏 var h = messageTitle.size.height; for (var i = 0; i < argAString.length; i++) {//添加消息内容 var m = new JControls.Label(argname + "lbM" + i, {x:0, y:h}, argAString[i]); m.size.width = argWH.width; m.textPos.x = 10; h += m.size.height; this.addControlInLast([m]); } this.size.height = h+20; }, onClick:function () {//点击后,删除对象 this.remove.call(this); JForm.show.call(JForm); } });
8、声音
这里写的比较简单。
JControls.Audio = Class.create({ audioData:null,//Audio数据 initialize:function (audio,loop) { this.setAudio(audio,loop); }, setAudio:function(audio,loop){ if(audio){ this.audioData = audio.data; if(loop)this.audioData.loop=true; } }, play:function () { if (this.audioData)this.audioData.play(); }, pause:function () { if (this.audioData)this.audioData.pause(); } });
9、时钟
时钟只有一个,所有的动画和移动,都是由它来驱动的。
var JTick=null; JControls.Tick = Class.create({ time:40,//间隔时间 fun:[],//要循环显示的对象数组 handle:null,//句柄 initialize:function(time){ this.time=time; this.fun=[]; this.handle=null; JTick=this; }, begin:function(){ this.handle=setTimeout(this.runOneTime, this.time); }, end:function(){ if(this.handle)clearTimeout(this.handle); }, add:function(aObj){ if(aObj){ for (var i = 0; i < aObj.length; i++) { this.fun[this.fun.length]=aObj[i]; } } }, delete:function(obj){ if(obj){ for(var i=0;i<this.fun.length;i++){ if(this.fun[i].name==obj.name){ for(var j=i;j<this.fun.length-1;j++){ this.fun[j]=this.fun[j+1]; } this.fun.length--; } } } }, runOneTime:function(){ JTick.end(); for(var i=0;i<JTick.fun.length;i++){ if(JTick.fun[i])JTick.fun[i].show.call(JTick.fun[i]); } JTick.handle=setTimeout(JTick.runOneTime, JTick.time); } });
至此,基本对象已经设计完成,下篇开始就要设计游戏中的具体对象了。
相关文章推荐
- 学习HTML5开发RPG游戏第三步>基本对象设计<二>
- 学习HTML5开发RPG游戏第三步>基本对象设计<三>
- 学习HTML5开发RPG游戏第四步>游戏对象设计
- 学习HTML5开发RPG游戏第五步>游戏界面设计<一>
- 学习HTML5开发RPG游戏第五步>游戏界面设计<二>(结束)
- 学习HTML5开发RPG游戏第一步>准备
- OpenCV 2 学习笔记(12): 算法的基本设计模式<3>:单例模式(Singleton pattern)
- JavaScript基础学习<四>基本数据和引用类型
- <<Android源码设计模式解析与实战>>读书笔记----- Android NDK开发学习
- OpenCV 2 学习笔记(10): 算法的基本设计模式<1>:策略模式(strategy pattern)
- OpenCV 2 学习笔记(13): 算法的基本设计模式<4> :使用Model-View-Controller模式创建一个应用程序
- 面向对象系统设计与开发专题<3>__开发过程
- OpenCV 2 学习笔记(11): 算法的基本设计模式<2>:使用Controller
- 学习HTML5开发RPG游戏第二步>资源预加载
- LDAP学习笔记<四>jldap实现Java对LDAP的基本操作
- 面向对象系统分析与开发专题<1>__基本单位-类
- 面向对象系统分析与设计专题<7>__UML用例图之泛化(generalization)、扩展(extend)和包含(include)关系
- 学习笔记——JAVA设计模式<4>原型模式
- oracle开发之<<SQL Cookbook>>学习笔记整理:第二章 查询结果排序
- Oracle学习<四>