lufy's legend

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 7276|回复: 5
打印 上一主题 下一主题

LAnimation 使用?

[复制链接]

8

主题

0

好友

104

积分

士兵

Rank: 1

跳转到指定楼层
楼主
发表于 2014-8-29 15:54:25 |只看该作者 |倒序浏览
  • 模仿三国格斗那个游戏,做切图动画。数据生成也是模仿过来的。
  self.anime = new LAnimation(self,self.dList[0],self.animeList[0]);
    总是提示出如下错误。
    内部:p.onframe方法内部,拿到LAnimation的ImageArray 中的初始行列为,0,0的对象-obj。但是提示obj.width 不可读。是什么问题?前面 生成的格式不对导致的吗?
  • [color=red !important]
  • [color=red !important]Uncaught TypeError: Cannot read property 'width' of undefined
    [url=]lufylegend-1.9.0.js:4692[/url]

    • [color=red !important]p.onframe
      [url=]lufylegend-1.9.0.js:4692[/url]

    • [color=red !important]LAnimation
      [url=]lufylegend-1.9.0.js:46[/url]



回复

使用道具 举报

8

主题

0

好友

104

积分

士兵

Rank: 1

沙发
发表于 2014-8-29 15:58:52 |只看该作者
var  game_width =  window.innerWidth;
var  game_height = window.innerHeight;

var loadingLayer;
var gameBody;
var coverPage ;
var dataList ;
var force = [{nx:"100",nv:"400"},{nx:"200",nv:"300"},{nx:"300",nv:"100"},{nx:"200",nv:"50"},{nx:"100",nv:"0"},]

var loadData = [
               
{name : "background",path : "images/bg.png"},
{name : "arron",path : "images/arron.png"},
{name : "ready",path : "images/ready.png"},
{name : "jump",path : "images/jump.png"},
{name : "fly",path : "images/fly.png"},
{name : "stop",path : "images/stop.png"},
{name : "friend",path : "images/friend.png"},
{name : "tower",path : "images/tower.png"}

];



if(game_width>400){       
        game_width = 400;
}
if(game_height>600){
        game_height= 600;
}
window.onload = function(){
        init(60, "legend", game_width, game_height, main,LEvent.INIT);
}

function main(){
        LGlobal.backgroundColor ="#FFFFFF";
        if(LGlobal.mobile){
                LGlobal.align = LStageAlign.TOP_MIDDLE;
            LGlobal.stageScale = LStageScaleMode.NO_SCALE;
            LSystem.screen(LStage.FULL_SCREEN);
        }else{
                LGlobal.align = LStageAlign.TOP_MIDDLE ;
                LGlobal.stageScale = LStageScaleMode.NO_SCALE;
                LGlobal.aspectRatio = PORTRAIT;
                LSystem.screen(1);       
        }
       
        loadingLayer = new LoadingSample3();
        addChild(loadingLayer);
        LLoadManage.load(loadData, function(progress) {
                loadingLayer.setProgress(progress);
        }, imgLoadComplete);
       
}



function imgLoadComplete(result){
        dataList = result;
        removeChild(loadingLayer);
        loadingLayer = null;
        gameBody = new GameBody();
        addChild(gameBody);
       
}


function GameBody(){
       
        base(this,LSprite,[]);
        this.init();
       
       
}
GameBody.prototype.init = function(){
       
        var self = this;
        var lbitmap = new LBitmap(new LBitmapData(dataList["background"]));
        self.addChild(lbitmap);
        var talbit = new LBitmap(new LBitmapData(dataList["tower"]));
        talbit.x = game_width / 2;
        talbit.y =  game_height/3;
        self.flyCat = self.addFlyCat();
        self.friend =  self.addAttackCat();
        self.addChild(talbit);
        self.addChild(self.flyCat);
        self.addChild(self.friend);
        self.scaleX = game_width/(lbitmap.getWidth());
        self.scaleY = game_height/(lbitmap.getHeight());
       
        self.addEventListener(LEvent.ENTER_FRAME,self.onframe);
       
}

GameBody.prototype.onframe = function (event){
       
        var self =  event.target;
        var key = null;
        self.childList = self.childList.sort(function(a,b){return a.y - b.y;});
        for(key in self.childList){
               
                self.childList[key].onframe();
        }
       
}

GameBody.prototype.addFlyCat = function (){
        var  list = CharacterList.flycat();
        return new FlyCat(list);
}

GameBody.prototype.addAttackCat = function (){
        var  list = CharacterList.friend();
        var obj = new AttackCat(list);
        return obj;
}


function  FlyCat (list){
        base(this,LSprite,[]);
        this.init(list);
        this.anime = null;
        this.data = null;
        this.actionIndex = 0;
}

FlyCat.prototype.init = function (list){
        var self  = this;
        self.dList = list[0];
        self.animeList = list[1];
       
        self.x = game_width *5/8;
        self.y = game_height /4;
        console.log(self.dList);
        console.log(self.animeList[0][1])
        self.anime = new LAnimation(self,self.dList[0],self.animeList[0]);
       
       
       
       
}

FlyCat.prototype.setAnime =function (){
        self.data = self.dList[self.actionIndex];
        self.anime.bitmap.bitmapData = self.data;
        self.anime.bitmap.bitmapData.setCoordinate(0,0);
        self.anime.imageArray = self.coordinateList[self.actionIndex];
}

FlyCat.prototype.onframe = function (){
        var  self = this;
        self.anime.onframe();
}

function  AttackCat(list){
        base(this,LSprite,[]);
        this.init(list);
        this.anime = null;
        this.data = null;
        this.actionIndex = 0;
}

AttackCat.prototype.init = function (list){
        var self  = this;
        self.dList = list[0];
        self.animeList = list[1];
       
        var list = LGlobal.divideCoordinate(256,256,1,3);
        self.data = self.dList[0];
        self.action = self.animeList[0];
        self.x = game_width *5/8;
        self.y = game_height*3/4;
        self.anime = new LAnimation(self,self.dList[0],self.animeList[0]);
       
               
}

AttackCat.prototype.setAnime = function(){
        self.data = self.dList[self.actionIndex];
        self.anime.bitmap.bitmapData = self.data;
        self.anime.bitmap.bitmapData.setCoordinate(0,0);
        self.anime.imageArray = self.animeList[self.actionIndex];
        self.anime.addEventListener(LEvent.COMPLETE,self.overAnime);
}

AttackCat.prototype.overAnime = function (event){
        var self = event.target.parent;
        self.actionIndex ++;
        self.data = self.dList[self.actionIndex];
        self.anime.bitmap.bitmapData = self.data;
        self.anime.bitmap.bitmapData.setCoordinate(0,0);
        self.anime.imageArray = self.coordinateList[self.actionIndex];
        self.anime.removeEventListener(LEvent.COMPLETE,self.overAnime);
       
}

AttackCat.prototype.msClick = function (event){
        var  self = event.target.parent;
        self.flycat.actionIndex++;
        self.friend.actionIndex++;
        self.flycat.setAnime();
        self.friend.setAnime();
}


AttackCat.prototype.onframe = function (){
        var self = this;
        this.anime.onframe();
}


var  CharacterList ={
        flycat:function(){
                var dList = new Array();
                dList.push(new LBitmapData(dataList["ready"],0,0,85,128));
                dList.push(new LBitmapData(dataList["jump"],0,0,108,98));
                dList.push(new LBitmapData(dataList["fly"],0,0,138,46));
                dList.push(new LBitmapData(dataList["stop"],0,0,102,86));
                var coordinateList = new Array();
                var readyList  = LGlobal.divideCoordinate(256,256,1,3);
                coordinateList.push([readyList[0][0],readyList[0][1],readyList[0][2]]);
               
                var jumpList =  LGlobal.divideCoordinate(216,196,2,2);
                coordinateList.push([jumpList[0][0],jumpList[0][1],jumpList[1][0],jumpList[1][1]]);
               
                var flyList =  LGlobal.divideCoordinate(138,276,1,6);
                coordinateList.push([flyList[0][0],flyList[0][1],flyList[0][2],flyList[0][3],flyList[0][4],flyList[0][5]]);
               
                var stopList = LGlobal.divideCoordinate(204,258,2,3);
                coordinateList.push([stopList[0][0],stopList[0][1],stopList[0][2],stopList[1][0],stopList[1][1],stopList[1][2]]);
                return [dList,coordinateList];
        },
        friend:function(){
                var dList = new Array();
                var coordinateList = new Array();
                dList.push(new LBitmapData(dataList["friend"],0,0,180,171));
                var defList =  LGlobal.divideCoordinate(540,512,3,3);
                coordinateList.push([defList[0][0],defList[0][0],defList[0][0]]);
                coordinateList.push([defList[0][1],defList[0][1],defList[0][1]]);
                coordinateList.push([defList[0][1],defList[0][2],defList[1][0],defList[1][1],defList[1][2]]);
                coordinateList.push([defList[2][0],defList[2][0],defList[2][0]]);
                return [dList,coordinateList];
               
        }

}

回复

使用道具 举报

8

主题

0

好友

104

积分

士兵

Rank: 1

板凳
发表于 2014-8-29 16:05:09 |只看该作者
debug查看了下格式,发现数据填充的格式不对。
coordinateList.push([[defList[2][0],defList[2][0],defList[2][0]]]);
回复

使用道具 举报

37

主题

8

好友

9312

积分

诸侯王

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

地板
发表于 2014-8-29 21:43:54 |只看该作者
Ramsey 发表于 2014-8-29 16:05
debug查看了下格式,发现数据填充的格式不对。
coordinateList.push([[defList[2][0],defList[2][0],defLi ...

意思是已经解决了?
不回答与技术和引擎不相关的问题
回复

使用道具 举报

8

主题

0

好友

104

积分

士兵

Rank: 1

5#
发表于 2014-9-2 18:47:09 |只看该作者
lufy 发表于 2014-8-29 21:43
意思是已经解决了?

恩 ,现在遇到一个新的问题。

LSprite,当我去除一个图层时,会自动将图层事件监听,子对象(包括子对象的监听)全部去除吗?如果是这样,当我重新初始化游戏界面时,却发现有监听不起作用了。
回复

使用道具 举报

37

主题

8

好友

9312

积分

诸侯王

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

6#
发表于 2014-9-2 20:31:28 |只看该作者
Ramsey 发表于 2014-9-2 18:47
恩 ,现在遇到一个新的问题。

LSprite,当我去除一个图层时,会自动将图层事件监听,子对象(包括子对象 ...

已经在你另一个帖子中回复你了
不回答与技术和引擎不相关的问题
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

防止垃圾广告,请填写任意字符

Archiver|lufy's legend

GMT+8, 2024-5-3 01:05 , Processed in 0.054231 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部