2011-10-05 51 views
1

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

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

我觉得你最好问你的问题在这里https://groups.google.com/forum/#!forum/limejs 请检查下列事项:

  • 如果所有在KeyframeAnimation引用的spritesheet项目出现在你的spritesheet
  • 尝试使用setDelay,setLooping API方法代替直接分配
  • 我没有看到怪物变量定义...