本人還是小白,在做炮彈的時候遇到問題卡住了,炮彈能實作連續發射,圖片是連續幀,但是無法實作影片,知道用LAnimation,但總是報錯,求大神幫我解決問題。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body{
margin:0;
padding:0;
border:0px;
}
</style>
<script type="text/javascript" src="https://bbs.csdn.net/topics/js/lufylegend-1.10.1.min.js"></script>
</head>
<body>
<div id="legend"></div>
<script>
init(50,"legend",800,450,main);
var imgData = [
{name:"back",path:"./images/back.jpg"},
{name:"item7",path:"./images/shells.png"}
];
var imglist;
var itemLayer;
var anima;
var step=20,stepindex=0;
function main(){
LGlobal.setDebug(true);
LLoadManage.load(imgData,null,gameInit);
}
function gameInit(result){
//圖片加載
imglist = result;
//背景層
backLayer = new LSprite();
addChild(backLayer);
addBackGround();
//炮彈層
itemLayer= new LSprite();
backLayer.addChild(itemLayer);
addEvent();
}
function addEvent(){
backLayer.addEventListener(LEvent.ENTER_FRAME,onframe);
}
function onframe(){
//遍歷子集
for(var i=0;i<itemLayer.childList.length;i++){
itemLayer.childList[i].run();
if(itemLayer.childList[i].mode=="die"){
//洗掉前面的child
itemLayer.removeChild(itemLayer.childList[i]);
}
}
if(stepindex++ > step){
stepindex = 0;
addItem();
}
}
//添加食物的方法
function addItem(){
var item=new Item();
item.x = 20 ;
itemLayer.addChild(item);
}
//背景
function addBackGround(){
var bitmap=new LBitmap(new LBitmapData(imglist["back"]));
backLayer.addChild(bitmap);
}
//炮彈
function Item(){
base(this,LSprite,[]);
var self = this;
self.mode="";
var shall_list = LGlobal.divideCoordinate(256,256,2,4);
var shall_data =new LBitmapData(imglist["item7"],0,0,56,110);
var bitmap = new LBitmap(shall_data);
anima= new LAnimation(this.LSprite,shall_data,shall_list);
anima=addEventListener(LEvent.ENTER_FRAME,onframe);
self.addChild(anima);
}
//炮彈掉落
Item.prototype.run=function(){
var self=this;
self.y += 5;
}
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/60024.html
標籤:其它游戲引擎
