您的位置:首页 > Web前端 > HTML5

学习HTML5开发RPG游戏第三步>基本对象设计<四>

2013-12-18 17:14 483 查看
7、对话框

用于显示信息。

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);
}
});


至此,基本对象已经设计完成,下篇开始就要设计游戏中的具体对象了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息