标签:
增加游戏进度,界面title及游戏界面
//初始化引擎组件 init(50, "div_caiquan", 800, 400, main); //定义游戏层,加载进度层、游戏背景层,结果显示层,出拳操作层 var loadingLayer, backLayer, resultLayer, clickLayer; //定义游戏图片 //定义图片资源加载完成后返回的图片对象 var imglist = {}; //定义图片资源数组 var imgData = new Array( { name: "title", path: "../images/title.png" }, { name: "shitou", path: "../images/shitou.png" }, { name: "jiandao", path: "../images/jiandao.png" }, { name: "bu", path: "../images/bu.png" } ); //定义自己出拳图片,电脑出拳图片 var selfBitMap, enemyBitMap; //定义出拳图片数组 var showList = new Array(); //回调函数 function main() { //创建背景层 backLayer = new LSprite(); //将背景层添加到画布 addChild(backLayer); //创建加载进度层 loadingLayer = new LoadingSample3(); //将加载进度层添加到背景层 backLayer.addChild(loadingLayer); //loadingLayer.setProgress(35); //加载图片资源 LLoadManage.load( //图片数据数组 imgData, function (progress) { //显示加载进度 loadingLayer.setProgress(progress); }, function (result) { //加载完成 //result可以认为是一个map,资源列表中的资源可以按键获取 imglist = result; //移除加载进度层 backLayer.removeChild(loadingLayer); loadingLayer = null; //游戏初始化 gameInit(); } ); }; //游戏初始化 function gameInit() { //game begin //构造出拳图片数组 showList.push(new LBitmapData(imglist["shitou"])); showList.push(new LBitmapData(imglist["jiandao"])); showList.push(new LBitmapData(imglist["bu"])); //绘制游戏界面背景 backLayer.graphics.drawRect(10, "#008800", [0, 0, LGlobal.width, LGlobal.height], true, "#000000"); //显示游戏标题 var titleBitmap = new LBitmap(new LBitmapData(imglist["title"])); titleBitmap.x = (LGlobal.width - titleBitmap.width) / 2; titleBitmap.y = 10; backLayer.addChild(titleBitmap); //显示玩家出拳图片 selfBitMap = new LBitmap(showList[0]); selfBitMap.x = 400 - selfBitMap.width - 50; selfBitMap.y = 130; backLayer.addChild(selfBitMap); //显示电脑出拳图片 enemyBitMap = new LBitmap(showList[0]); enemyBitMap.x = 400 + 50; enemyBitMap.y = 130; backLayer.addChild(enemyBitMap); //玩家电脑名称设定 var nameText; nameText = new LTextField(); nameText.text = "玩家"; nameText.weight = "bolder"; nameText.color = "#ffffff"; nameText.size = 24; nameText.x = selfBitMap.x + (selfBitMap.width - nameText.getWidth()) / 2; nameText.y = 95; backLayer.addChild(nameText); nameText = new LTextField(); nameText.text = "电脑"; nameText.weight = "bolder"; nameText.color = "#ffffff"; nameText.size = 24; nameText.x = enemyBitMap.x + (enemyBitMap.width - nameText.getWidth()) / 2; nameText.y = 95; backLayer.addChild(nameText); //结果显示层初始化 initResultLayer(); //操作层初始化 initClickLayer(); }; function initResultLayer() { //创建结果显示层对象 resultLayer = new LSprite(); //绘制结果显示层,使用Sprite的graphic绘图 resultLayer.graphics.drawRect(4, ‘#ff8800‘, [0, 0, 150, 110], true, ‘#ffffff‘); //设置结果显示层位置 resultLayer.x = 10; resultLayer.y = 100; //添加到游戏背景层 backLayer.addChild(resultLayer); }; function initClickLayer() { //创建操作层对象 clickLayer = new LSprite(); //绘制操作层,使用Sprite的graphic绘图 clickLayer.graphics.drawRect(4, ‘#ff8800‘, [0, 0, 300, 110], true, ‘#ffffff‘); //设置操作层显示坐标 clickLayer.x = 250; clickLayer.y = 275; //添加到游戏背景层 addChild(clickLayer); };
finger-guessing game:2增加游戏进度,界面title及游戏界面
标签:
原文地址:http://www.cnblogs.com/zgqys1980/p/4453367.html