lufylegendRPG 开源引擎 API文档 - Yorhom's Game Box
lufylegendRPG开源引擎API文档
最终更新于2013/06/14
lufylegendRPG是基于lufylegend的HTML5游戏引擎。使用它时, 需要引入lufylegend.js。 包含了LTileMap,LCharacter,LTalk, LEffect等多个实用的类。 由于是基于lufylegend,所以你需要 了解一下lufylegend的用法,这样才能更合理,更快捷地运用 lufylegendRPG进行开发。 该引擎主要封装了lufylegend的一些 基本功能,使该引擎能更快地开发出一款RPG小游戏。 如果你还 没有接触过lufylegend,可以去官方网站下载它,同时结合API文 档学习它。 如果你已经对lufylegend很孰悉了,那就可以直接开 始学习lufylegendRPG。 相信lufylegend和lufylegendRPG能使你更 快地走进HTML5游戏开发的世界。 如果您还没有接触过lufylegend, 请到这里看看吧, 当您了解了lufylegend,运用该引擎才会感到方便。
lufylegendRPG引擎下载
lufylegendRPG引擎讨论区
联系作者
lufylegendRPG 使用流程
■详细介绍:
1,在官方网站上下载lufylegendRPG和lufylegend
2,引入lufylegendRPG和lufylegend
3,通过lufylegend中的init函数初始化引擎
4,开始你的编程之旅
■举例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>demo</title> </head> <body> <div id="mylegend">loading……</div> <script type="text/javascript" src="../lufylegend-x.x.x.min.js"></script> <script type="text/javascript" src="../lufylegendrpg-x.x.x.min.js"></script> <script> init(50,"mylegend",800,480,main); function main(){ alert("感谢您使用lufylegendRPG库件,现在你就可以开始你的编程之旅了!"); } </script> </body> </html>
LRPGStage.closePage()
■详细介绍:
关闭标签页,通常用于关闭游戏
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ if(LKeyboard.isEsc() == true)LRPGStage.closePage(); }); }
LKeyboard.isEsc()
■详细介绍:
判断是否按下Esc
※使用该方法要开启快捷键
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ if(LKeyboard.isEsc() == true)alert("Esc"); }); }
LKeyboard.isEnter()
■详细介绍:
判断是否按下Enter
※使用该方法要开启快捷键
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ if(LKeyboard.isEnter() == true)alert("Enter"); }); }
LKeyboard.isCtrl()
■详细介绍:
判断是否按下Ctrl
※使用该方法要开启快捷键
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ if(LKeyboard.isCtrl() == true)alert("Ctrl"); }); }
LKeyboard.isShift()
■详细介绍:
判断是否按下Shift
※使用该方法要开启快捷键
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ if(LKeyboard.isShift() == true)alert("Shift"); }); }
LKeyboard.getKeyCode()
■详细介绍:
取出按键的对应值
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ alert(LKeyboard.getKeyCode()); }); }
LKeyboard.getKeyName()
■详细介绍:
取出按键的名称
■举例:
LRPGStage.setShortcuts(true); function main(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,function(){ alert(LKeyboard.getKeyName()); }); }
LTilemap(
data,
img,
width,
height,
tdata
)
■详细介绍:
用地图块平铺一张地图
■可用属性:
x:整张地图的x坐标
y:整张地图的y坐标
imgData:地图图片数据
mapData:地图显示数据
partHeight:地图块高度
partWidth:地图块宽度
■参数:
data:地图数组,格式为一个二维数组
img:装有小地图块的一张大图
width:地图块宽度
height:地图块高度
tdata:地形数组,格式为一个二维数组
■举例:
init(50,"mylegend",500,600,main); var map = [ [11,10,10,10,11], [11,11,10,10,11], [10,10,11,11,11], [10,10,10,10,11] ]; var mapdata = [ [1,0,0,0,1], [1,1,0,0,1], [0,0,1,1,1], [0,0,0,0,1] ]; var mapObj = new LTileMap(map,datalist[mapimg],48,48,mapdata); addChild(mapObj);
setData(data,img,width,height,tdata)
■详细介绍:
重设地图数据
■参数:
data:地图数组,格式为一个二维数组
img:装有小地图块的一张大图
width:地图块宽度
height:地图块高度
tdata:地形数组,格式为一个二维数组
■举例:
init(50,"mylegend",500,600,main); var map = [ [11,10,10,10,11], [11,11,10,10,11], [10,10,11,11,11], [10,10,10,10,11] ]; var mapdata = [ [1,0,0,0,1], [1,1,0,0,1], [0,0,1,1,1], [0,0,0,0,1] ]; var mapObj = new LTileMap(); addChild(mapObj); function main(){ mapObj.setData(map,datalist[mapimg],48,48,mapdata); }
getWidth()
■详细介绍:
取出整张大地图的宽度
■举例:
init(50,"mylegend",500,600,main); var map = [ [11,10,10,10,11], [11,11,10,10,11], [10,10,11,11,11], [10,10,10,10,11] ]; var mapdata = [ [1,0,0,0,1], [1,1,0,0,1], [0,0,1,1,1], [0,0,0,0,1] ]; var mapObj = new LTileMap(map,datalist[mapimg],48,48,mapdata); addChild(mapObj); function main(){ alert(mapObj.getWidth()); }
getHeight()
■详细介绍:
取出整张大地图的高度
■举例:
init(50,"mylegend",500,600,main); var map = [ [11,10,10,10,11], [11,11,10,10,11], [10,10,11,11,11], [10,10,10,10,11] ]; var mapdata = [ [1,0,0,0,1], [1,1,0,0,1], [0,0,1,1,1], [0,0,0,0,1] ]; var mapObj = new LTileMap(map,datalist[mapimg],48,48,mapdata); addChild(mapObj); function main(){ alert(mapObj.getHeight()); }
showData()
■详细介绍:
显示地图数据,并会在地图上标明地形
■举例:
init(50,"mylegend",500,600,main); var map = [ [11,10,10,10,11], [11,11,10,10,11], [10,10,11,11,11], [10,10,10,10,11] ]; var mapdata = [ [1,0,0,0,1], [1,1,0,0,1], [0,0,1,1,1], [0,0,0,0,1] ]; var mapObj = new LTileMap(); addChild(mapObj); function main(){ mapObj.showData(); }
LEffect()
■详细介绍:
为RPG场景上添加特殊效果
■举例:
init(50,"mylegend",500,600,main); function main(){ var layer = new LSprite(); addChild(layer); layer.graphics.drawRect(5,"dimgray",[0,0,LStage.width,LStage.height],true,"black"); var effect = new LEffect(); addChild(effect); effect.raining(); }
raining(speed,size)
■参数:
speed:雨点下落的速度
size:雨点的尺寸
■详细介绍:
为RPG场景上添加下雨的效果
■举例:
init(50,"mylegend",500,600,main); function main(){ var layer = new LSprite(); addChild(layer); layer.graphics.drawRect(5,"dimgray",[0,0,LStage.width,LStage.height],true,"black"); var effect = new LEffect(); addChild(effect); effect.raining(50,5); }
raining(speed,size)
■参数:
speed:雪花下落的速度
size:雪花的半径
■详细介绍:
为RPG场景上添加下雪的效果
■举例:
init(50,"mylegend",500,600,main); function main(){ var layer = new LSprite(); addChild(layer); layer.graphics.drawRect(5,"dimgray",[0,0,LStage.width,LStage.height],true,"black"); var effect = new LEffect(); addChild(effect); effect.snowing(50,2); }
sleeting(speed,size)
■参数:
speed:雪花和雨点下落的速度
size:为一个数组,形式为[雪花的半径,雨点的尺寸]
■详细介绍:
为RPG场景上添加雨夹雪的效果
■举例:
init(50,"mylegend",500,600,main); function main(){ var layer = new LSprite(); addChild(layer); layer.graphics.drawRect(5,"dimgray",[0,0,LStage.width,LStage.height],true,"black"); var effect = new LEffect(); addChild(effect); effect.sleeting(50,[2,5]); }
LCurtainSample1(
speed,
onClosing,
onComplete
)
■参数:
speed:幕布合拢的速度
onClosing:当幕布合拢时调用此函数
onComplete:当幕布合拢展开完成时调用此函数
■详细介绍:
用来显示遮屏效果之一
■举例:
init(50,"mylegend",500,600,main); function main(){ var curtain = new LCurtainSample1(); addChild(curtain); }
LCurtainSample2(
speed,
onClosing,
onComplete
)
■参数:
speed:幕布合拢的速度
onClosing:当幕布合拢时调用此函数
onComplete:当幕布合拢展开完成时调用此函数
■详细介绍:
用来显示遮屏效果之一
■举例:
init(50,"mylegend",500,600,main); function main(){ var curtain = new LCurtainSample2(); addChild(curtain); }
LCurtainSample3(
speed,
onClosing,
onComplete
)
■参数:
speed:幕布合拢的速度
onClosing:当幕布合拢时调用此函数
onComplete:当幕布合拢展开完成时调用此函数
■详细介绍:
用来显示遮屏效果之一
■举例:
init(50,"mylegend",500,600,main); function main(){ var curtain = new LCurtainSample3(); addChild(curtain); }
LTalk(content)
■参数:
content:对话内容
■可用属性:
x:对话区x坐标
y:对话区y坐标
talkIndex:对话序号
textWidth:文本区宽度
■详细介绍:
用来显示对话,参数的格式如下
var talkContent = [ {face:头像素材,name:"人物名称",msg:"对话内容"}, {face:头像素材,name:"人物名称",msg:"对话内容"} ];
※LTalk构造时所传的对话内容参数是一个数组套JSON的格式,它要在游戏图片加载完成后再初始化,否则显示不出对话头像。
■举例:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>LTalk</title> <script type="text/javascript" src="../lufylegend-1.7.6.min.js"></script> <script type="text/javascript" src="../lufylegendrpg-1.0.0.js"></script> <script> init(30,"legend",480,320,main); LRPGStage.setShortcuts(true); LGlobal.setDebug(true); var backLayer,loadingLayer,talkLayer; var talk; var talkContent; var talkNum = 0; var loadData = [ {name:"yorhom_face",path:"./yorhom.jpg"}, {name:"lufy_face",path:"./lufy.jpg"} ]; var imglist = []; function main(){ //加入进度条 loadingLayer = new LoadingSample1(); addChild(loadingLayer); //加载图片并显示进度 LLoadManage.load( loadData, function(progress){ loadingLayer.setProgress(progress); }, gameInit ); } function gameInit(result){ removeChild(loadingLayer); imglist = result; //初始化层 backLayer = new LSprite(); addChild(backLayer); talkLayer = new LSprite(); backLayer.addChild(talkLayer); //加入操作按钮 addEvent(); //添加对话内容 talkContent = [ {name:"[Yorhom]",msg:"你好,lufy",face:imglist["yorhom_face"]}, {name:"[lufy]",msg:"你好,yorhom",face:imglist["lufy_face"]}, {name:"[Yorhom]",msg:"lufylegend最新版本是哪个版本啊?",face:imglist["yorhom_face"]}, {name:"[lufy]",msg:"……你不知道自己看吗?",face:imglist["lufy_face"]}, {name:"[Yorhom]",msg:"……说得也是",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; talk = new LTalk(talkContent); talkLayer.addChild(talk); talkLayer.addEventListener(LMouseEvent.MOUSE_DOWN,say); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; } function addEvent(){ LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_UP,say); } function say(){ if(talkNum < talkContent.length){ //输出对话 talk.wind(talkNum,function(){talkNum++;}); } } </script> </head> <body> <div id="legend"></div> </body> </html>
setFaceStyle(style)
■参数:
style:人物头像的样式,格式是一个json对象,如下:{x:头像x坐标,y:头像y坐标}
■详细介绍:
用来设置人物头像的样式
■举例:
var talkLayer = new LSprite(); addChild(talkLayer); //添加对话内容 var talkContent = [ {name:"[Yorhom]",msg:"你好",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; var talk = new LTalk(talkContent); talkLayer.addChild(talk); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; //显示对话 talk.wind();
setNameStyle(style)
■参数:
style:人物名称的样式,格式是一个json对象,如下:{x:名称x坐标,y:名称y坐标,color:字体颜色,font文字的格式:,size:字体大小}
■详细介绍:
用来设置人物名称的样式
■举例:
var talkLayer = new LSprite(); addChild(talkLayer); //添加对话内容 var talkContent = [ {name:"[Yorhom]",msg:"你好",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; var talk = new LTalk(talkContent); talkLayer.addChild(talk); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; //显示对话 talk.wind();
setMsgStyle(style)
■参数:
style:对话内容的样式,格式是一个json对象,如下:{x:对话内容x坐标,y:对话内容y坐标,color:字体颜色,font文字的格式:,size:字体大小}
■详细介绍:
用来设置对话内容的样式
■举例:
var talkLayer = new LSprite(); addChild(talkLayer); //添加对话内容 var talkContent = [ {name:"[Yorhom]",msg:"你好",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; var talk = new LTalk(talkContent); talkLayer.addChild(talk); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; //显示对话 talk.wind();
wind(num,completeFunc)
■参数:
num:显示对话序号
completeFunc:每次对话完成后调用此函数
■详细介绍:
用来显示对话
■举例:
var talkLayer = new LSprite(); addChild(talkLayer); //添加对话内容 var talkContent = [ {name:"[Yorhom]",msg:"你好",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; var talk = new LTalk(talkContent); talkLayer.addChild(talk); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; //显示对话 talk.wind();
clear()
■详细介绍:
用来清空对话对象上的内容
■举例:
var talkLayer = new LSprite(); addChild(talkLayer); //添加对话内容 var talkContent = [ {name:"[Yorhom]",msg:"你好",face:imglist["yorhom_face"]}, ]; //加入对话 talkLayer.graphics.drawRect(5,"black",[20,15,400,130],true,"black"); talkLayer.alpha = 0.8; var talk = new LTalk(talkContent); talkLayer.addChild(talk); //设置样式 talk.setNameStyle({x:160,y:40,color:"white",size:12}); talk.setMsgStyle({x:160,y:70,color:"white",size:10}); talk.setFaceStyle({x:30,y:30}); talk.textWidth = 260; //显示对话 talk.wind(0,function(){ talk.clear(); });
LCharacter(
data,
row,
col,
speed,
isFighter
)
■参数:
data:人物图片
row:将图片切成多少行,以方便执行动画
col:将图片切成多少列,以方便执行动画
speed:人物动画播放频率相对屏幕刷新频率的倍数
isFighter:是否处于战斗状态
■可用属性:
x:人物x坐标
y:人物y坐标
anime:人物动画对象
mode:人物状态,可以为任何值
index:人物序号
effect:人物特效
hp:体力值
attack:攻击力
defense:防御力
※hp,attack,defense是在参数isFighter为true时可用
※effect可以赋值为LSkill.avatar,LSkill.flicker
■详细介绍:
lufylegendRPG中一个人物类
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); function onframe(){ chara.onframe(); }
setData(data,row,col,speed,isFighter)
■参数:
data:人物图片
row:将图片切成多少行,以方便执行动画
col:将图片切成多少列,以方便执行动画
speed:人物动画播放频率相对屏幕刷新频率的倍数
isFighter:是否处于战斗状态
■详细介绍:
重新设置人物数据
onframe()
■详细介绍:
播放一行人物动画
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); function onframe(){ chara.onframe(); }
addActionEventListener(
type,
func,
)
■参数:
type:事件类型
func:响应事件的函数
■详细介绍:
加入人物动画监听事件
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); chara.addActionEventListener(LEvent.COMPLETE,function(){ trace("hello"); }); function onframe(){ chara.onframe(); }
setAction(
rowIndex,
colIndex,
mode,
isMirror
)
■参数:
rowIndex:播放动画的行号
colIndex:播放动画的列号
mode:(1,0,-1)分别代表(正序播放,静止,倒序播放)
isMirror:Boolean型,当设定为true的时候,图片显示为水平翻转后的镜像
■详细介绍:
设置播放动画的行号,列号,播放顺序和镜像
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); chara.setAction(1,0,1,true); function onframe(){ chara.onframe(); }
getAction()
■详细介绍:
得到当前动画播放的行号,列号,播放顺序和镜像。
返回值:结果数组[行号,列号,播放模式,是否为镜像]
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); var animeData = chara.getAction(1,0,1,true); alert(animeData); function onframe(){ chara.onframe(); }
moveTo(
x,
y,
timer,
type,
style,
completefunc
)
■参数:
x:移动到的x坐标
y:移动到的y坐标
timer:缓动执行的时间
type:缓动类型
style:移动方式
completefunc:完成后调用此函数
※style可以赋值为LMoveStyle.horizontal,LMoveStyle.vertical,LMoveStyle.direct
■详细介绍:
使人物以缓动的形式移动到指定位置
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); chara.moveTo(100,100,1,Quad.easeIn,LMoveStyle.vertical,function(){alert("complete");}); function onframe(){ chara.onframe(); }
addName(name,style)
■参数:
name:文字内容
style:文字样式
※style是一个数组,形式如下:[x,y,文字颜色,文字尺寸,文字的格式]
■详细介绍:
给人物身旁添加文字,添加的文字跟随人物一起移动。通常用来显示hp值,人物名称等
■举例:
var backLayer = new LSprite(); addChild(backLayer); var chara = new LCharacter(imglist["player"],4,4,3); backLayer.addChild(chara); backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); chara.addName("yorhom",[10,58,"red","12","黑体"]); function onframe(){ chara.onframe(); }
LHitList(objectA,sprite,type)
■参数:
objectA:检测对象A
sprite:检测对象B为这个LSprite中的所有成员
type:检测碰撞类型
※type的值可以为"TestRect"和"TestArc","TestRect"代表矩型碰撞,"TestArc"代表圆形碰撞
■详细介绍:
获取一个对象与其他对象碰撞的列表
■举例:
init(30,"mylegend",800,450,main); LStage.setDebug(true); var back,hita,hitb,hitc,hit; var list; var label; function main(){ back = new LSprite(); addChild(back); back.addEventListener(LMouseEvent.MOUSE_DOWN,mousedown); back.graphics.drawRect(5,"dimgray",[0, 0, LStage.width, LStage.height],true,"white"); hitb = new LSprite(); hitb.x = 200; hitb.y = 100; back.addChild(hitb); hitb.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hitc = new LSprite(); hitc.x = 300; hitc.y = 100; back.addChild(hitc); hitc.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hita = new LSprite(); hita.x = 100; hita.y = 100; hita.alpha = 0.8; back.addChild(hita); hita.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hit = new LHitList(hita,back); var button = new LButtonSample2("重置",20); button.backgroundCorl = "orange"; button.x = 700; button.y = 350; addChild(button); button.addEventListener(LMouseEvent.MOUSE_DOWN,clear) } function addText(sprite){ lable = new LTextField(); lable.size = 10; lable.x = 20; lable.y = 20; lable.color = "#ff0000"; lable.text = "我被碰到了"; sprite.addChild(lable); } function mousedown(event){ hit.clearList(); hita.x = event.selfX - 50; hita.y = event.selfY - 50; list = hit.getList(); change(); } function change(){ for(var key in list){ addText(list[key]); } } function clear(){ hita.x = 100; hita.y = 100; hita.alpha = 0.8; hitb.removeAllChild(); hitc.removeAllChild(); }
getList()
■详细介绍:
获取列表,返回值是一个数组
■举例:
init(30,"mylegend",800,450,main); LStage.setDebug(true); var back,hita,hitb,hitc,hit; var list; var label; function main(){ back = new LSprite(); addChild(back); back.addEventListener(LMouseEvent.MOUSE_DOWN,mousedown); back.graphics.drawRect(5,"dimgray",[0, 0, LStage.width, LStage.height],true,"white"); hitb = new LSprite(); hitb.x = 200; hitb.y = 100; back.addChild(hitb); hitb.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hitc = new LSprite(); hitc.x = 300; hitc.y = 100; back.addChild(hitc); hitc.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hita = new LSprite(); hita.x = 100; hita.y = 100; hita.alpha = 0.8; back.addChild(hita); hita.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hit = new LHitList(hita,back); var button = new LButtonSample2("重置",20); button.backgroundCorl = "orange"; button.x = 700; button.y = 350; addChild(button); button.addEventListener(LMouseEvent.MOUSE_DOWN,clear) } function addText(sprite){ lable = new LTextField(); lable.size = 10; lable.x = 20; lable.y = 20; lable.color = "#ff0000"; lable.text = "我被碰到了"; sprite.addChild(lable); } function mousedown(event){ hit.clearList(); hita.x = event.selfX - 50; hita.y = event.selfY - 50; list = hit.getList(); change(); } function change(){ for(var key in list){ addText(list[key]); } } function clear(){ hita.x = 100; hita.y = 100; hita.alpha = 0.8; hitb.removeAllChild(); hitc.removeAllChild(); }
clearList()
■详细介绍:
清空列表,以便判断第二次碰撞
■举例:
init(30,"mylegend",800,450,main); LStage.setDebug(true); var back,hita,hitb,hitc,hit; var list; var label; function main(){ back = new LSprite(); addChild(back); back.addEventListener(LMouseEvent.MOUSE_DOWN,mousedown); back.graphics.drawRect(5,"dimgray",[0, 0, LStage.width, LStage.height],true,"white"); hitb = new LSprite(); hitb.x = 200; hitb.y = 100; back.addChild(hitb); hitb.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hitc = new LSprite(); hitc.x = 300; hitc.y = 100; back.addChild(hitc); hitc.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hita = new LSprite(); hita.x = 100; hita.y = 100; hita.alpha = 0.8; back.addChild(hita); hita.graphics.drawRect(5,"dimgray",[0, 0, 100, 100],true,"gray"); hit = new LHitList(hita,back); var button = new LButtonSample2("重置",20); button.backgroundCorl = "orange"; button.x = 700; button.y = 350; addChild(button); button.addEventListener(LMouseEvent.MOUSE_DOWN,clear) } function addText(sprite){ lable = new LTextField(); lable.size = 10; lable.x = 20; lable.y = 20; lable.color = "#ff0000"; lable.text = "我被碰到了"; sprite.addChild(lable); } function mousedown(event){ hit.clearList(); hita.x = event.selfX - 50; hita.y = event.selfY - 50; list = hit.getList(); change(); } function change(){ for(var key in list){ addText(list[key]); } } function clear(){ hita.x = 100; hita.y = 100; hita.alpha = 0.8; hitb.removeAllChild(); hitc.removeAllChild(); }
LBackground(data,mode)
■参数:
data:背景图片数据,为一个LBitmapData对象
mode:背景显示模式
※mode可以赋值为LBackgroundStyle.tile,LBackgroundStyle.scale。
当为LBackgroundStyle.tile时,背景图如果小于界面大小则平铺以至填满界面
当为LBackgroundStyle.scale时,背景图如果小于界面大小则拉伸以至填满界面
■详细介绍:
显示一张背景图
■举例:
init(30,"mylegend",800,450,main); var bitmapdata = new LBitmapData(datalist["back01"]); var background = new LBackground(bitmapdata,LBackgroundStyle.scale); addChild(background);
showData()
■详细介绍:
显示背景数据
※必须是在debug模式下才能显示
■举例:
init(30,"mylegend",800,450,main); var bitmapdata = new LBitmapData(datalist["back01"]); var background = new LBackground(bitmapdata,LBackgroundStyle.scale); addChild(background); background.showData();
LSceneData(
backObj,
charaList,
talkContent,
weather
)
■参数:
backObj:背景图对象,可以是LBackground对象,也可以是LTileMap对象
charaList:人物列表
talkContent:对话列表
weather:LEffect对象
※charaList的形式如下:
var charaList = [ //chara代表人物类型 //data代表人物图片数据 //row就是图片切为动画小图时的行号 //col就是图片切为动画小图时的列号 //speed为人物动画频率 //x为人物x坐标,如果backObj是一个LTileMap对象,则x为人物所在地图块的列号 //y为人物y坐标,如果backObj是一个LTileMap对象,则x为人物所在地图块的行号 {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, //当chara的值为"player"时,该对象为可控制的人物 {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3},//当chara不是"player"时,需要添加talkIndex属性来确认所对应的对话 {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ];
※talkContent的形式如下:
var talkContent = { 1:[ //如果一个角色的talkIndex是1,与其对话显示对话为这一段对话 {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ //如果一个角色的talkIndex是2,与其对话显示对话为这一段对话 {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] };
■详细介绍:
保存场景数据
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); addChild(stageObj);
setData(
backObj,
charaList,
talkContent,
weather
)
■参数:
backObj:背景图对象,可以是LBackground对象,也可以是LTileMap对象
charaList:人物列表
talkContent:对话列表
weather:LEffect对象
※charaList的形式如下:
var charaList = [ //chara代表人物类型 //data代表人物图片数据 //row就是图片切为动画小图时的行号 //col就是图片切为动画小图时的列号 //speed为人物动画频率 //x为人物x坐标,如果backObj是一个LTileMap对象,则x为人物所在地图块的列号 //y为人物y坐标,如果backObj是一个LTileMap对象,则x为人物所在地图块的行号 {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, //当chara的值为"player"时,该对象为可控制的人物 {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3},//当chara不是"player"时,需要添加talkIndex属性来确认所对应的对话 {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ];
※talkContent的形式如下:
var talkContent = { 1:[ //如果一个角色的talkIndex是1,与其对话显示对话为这一段对话 {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ //如果一个角色的talkIndex是2,与其对话显示对话为这一段对话 {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] };
■详细介绍:
重新设置场景数据
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(); stageData.setData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); addChild(stageObj);
showData()
■详细介绍:
显示场景数据
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); addChild(stageObj); stageObj.showData();
LScene(data)
■参数:
data:场景数据,为一个LSceneData对象
■可用属性:
x:场景x坐标
y:场景y坐标
player:可操控的人物对象
playerX:人物在地图中的列号
playerY:人物在地图中的行号
■详细介绍:
显示一个场景对象
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); addChild(stageObj);
addMoveEventListener(type,func)
■参数:
type:事件类型
func:调用函数
■详细介绍:
使人物在地图上每移动完一格就触发此事件
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.addMoveEventListener(LEvent.COMPLETE,function(){ alert("COMPLETE"); }); addChild(stageObj);
setMap(canMove,cannotMove)
■参数:
canMove:在地形数据中代表可以移动的数字
cannotMove:在地形数据中代表不可以移动的数字
■详细介绍:
改变在地形数据中代表可以移动和不可以移动的数字
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.setMap(0,1); addChild(stageObj);
setCharacter(
moveLeft,
moveRight,
moveUp,
moveDown
)
■参数:
moveLeft:人物在向左行走时在动画中的行号
moveRight:人物在向右行走时在动画中的行号
moveUp:人物在向上行走时在动画中的行号
moveDown:人物在向下行走时在动画中的行号
■详细介绍:
改变人物行走的样式
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.setCharacter(0,1,2,3); addChild(stageObj);
movePlayer(dir)
■参数:
dir:人物行动方向
※参数dir可为LPlayer.LEFT(向左移动),LPlayer.RIGHT(向右移动),LPlayer.UP(向上移动),LPlayer.DOWN(向下移动)
■详细介绍:
运用此方法可以自行操控人物移动
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.movePlayer(LPlayerMove.LEFT); addChild(stageObj);
startTalk()
■详细介绍:
运用此方法可以操控人物对话(当有其他角色在主角附近时才会开始对话)
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.startTalk(); addChild(stageObj);
setTalkStyle(
faceStyle,
nameStyle,
msgStyle,
back,
textWidth
)
■参数:
faceStyle:对话人头像样式,格式如下:{x:x,y:y}
nameStyle:对话人名称样式,格式如下:{x:x,y:y,size:文字尺寸,color:文字颜色,font:文字的格式}
msgStyle:对话内容样式,格式如下:{x:x,y:y,size:文字尺寸,color:文字颜色,font:文字的格式}
back:背景
textWidth:对话区宽度
■详细介绍:
运用此方法可以设置人物对话的样式
■举例:
var map = [ [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0], [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0], [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0], [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0], [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0], [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0], [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0], [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0], [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0] ]; var mapdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1], [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1], [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1] ]; var talkContent = { 1:[ {face:datalist["m"],name:"[鸣人]",msg:"你们在干什么啊?"}, {face:datalist["n"],name:"[黑衣忍者甲]",msg:"我们在喝茶。"} ], 2:[ {face:datalist["n"],name:"[黑衣忍者乙]",msg:"我们在喝茶,你不要打扰我们。"}, {face:datalist["m"],name:"[鸣人]",msg:"....."} ] }; var charaList = [ {chara:"player",data:datalist["player"],row:4,col:4,speed:3,x:7,y:8}, {chara:"npc",talkIndex:1,data:datalist["npc"],row:4,col:4,speed:3,x:8,y:3}, {chara:"npc",talkIndex:2,data:datalist["npc"],row:4,col:4,speed:3,x:10,y:3} ]; var mapObj = new LTileMap(map,datalist["map"],32,32,mapdata); var stageData = new LSceneData(mapObj,charaList,talkContent); var stageObj = new LScene(stageData); stageObj.setTalkStyle({x:-80,y:20},{x:20,y:55,size:12,color:"lightgray"},{x:20,y:85,size:10,color:"lightgray"},talkBoard,200); addChild(stageObj);