spritesheet动画

时间:2011-10-05 17:33:25

标签: javascript json animation sprite-sheet

我正在尝试运行一个脚本,但我遇到了一些麻烦。我之前只使用过一次javascript,但现在我必须在网页上来回制作角色动画并继续直到页面关闭。我的调试器说第57行有一个引用错误,但我确信这不是唯一的问题。如果有人可以看看代码,看看是否有任何东西弹出,我将不胜感激。

goog.provide('mysprites');


goog.require('lime');
goog.require('lime.Director');
goog.require('lime.Layer');
goog.require('lime.Sprite');
goog.require('lime.fill.Frame');
goog.require('lime.animation.KeyframeAnimation');
goog.require('lime.animation.MoveBy');
goog.require('lime.SpriteSheet');
goog.require('lime.animation.MoveTo');
goog.require('lime.animation.Sequence');
goog.require('lime.animation.Loop');
goog.require('lime.animation.Delay');
goog.require('lime.parser.JSON');
goog.require('lime.ASSETS.spaceman.json');


mysprites.WIDTH = 600;
mysprites.HEIGHT = 400;


mysprites.start = function() {

//director
mysprites.director = new lime.Director(document.body, mysprites.WIDTH, mysprites.HEIGHT);
mysprites.director.makeMobileWebAppCapable();

var gamescene = new lime.Scene;

layer = new lime.Layer();
gamescene.appendChild(layer);

// load the spritesheet
mysprites.ss = new lime.SpriteSheet('assets/spaceman.png',lime.ASSETS.spaceman.json,lime.parser.JSON);

var sprite = mysprites.makeMonster().setPosition(100,100);
layer.appendChild(sprite);

//move
var moveRight = new lime.animation.MoveTo(874, 100)
    .setSpeed(1)
    .setEasing(lime.animation.Easing.LINEAR);

var moveLeft = new lime.animation.MoveTo(100, 100)
    .setSpeed(1)
    .setEasing(lime.animation.Easing.LINEAR);


// show animation
var anim = new lime.animation.KeyframeAnimation();
anim.delay= 1/10;
for(var i=0;i<=9;i++){
    anim.addFrame(mysprites.ss.getFrame('spaceman-'+'w'+'0'+i+'.png'));
}
monster.runAction(anim);

    var anim2 = new lime.animation.KeyframeAnimation();
anim.delay= 1/10;
for(var i=0;i<=9;i++){
    anim.addFrame(mysprites.ss.getFrame('spaceman-'+'e'+'0'+i+'.png'));
}
monster.runAction(anim2);

goog.events.listen(moveRight,lime.animation.Event.STOP, function () {
    setTimeout(function () {
        monster.runAction(moveLeft);
    }, 500);
});

goog.events.listen(moveLeft,lime.animation.Event.STOP, function () {
    setTimeout(function () {
        monster.runAction(moveRight);
    }, 500);
});   
};

mysprites.makeMonster = function(){
var sprite = new lime.Sprite().setPosition(200,200)
    .setFill(mysprites.ss.getFrame('spaceman-s00.png'));
//layer.appendChild(sprite);

return sprite;
};

goog.exportSymbol('mysprites.start', mysprites.start);

1 个答案:

答案 0 :(得分:1)

我认为你最好在这里问你的问题https://groups.google.com/forum/#!forum/limejs 请检查以下内容:

  • 如果您的spritesheet中存在KeyframeAnimation中引用的所有spritesheet项目
  • 尝试使用setDelay,setLooping API方法而不是直接赋值
  • 我没看到怪物变量定义......