精灵表动画

发布于 2024-12-08 11:56:37 字数 2449 浏览 0 评论 0原文

我正在尝试运行脚本,但遇到了一些麻烦。我以前只使用过一次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);

I'm trying to get a script to run but I'm having a little trouble. I've only used javascript once before, but now i have to make a character animation walk back and forth on a web page and continue until the page is closed. My debugger says there is a reference error on line 57, but i'm sure thats not the only problem. If anyone could take a look at the code and see if anything pops out at them, I would be grateful.

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-12-15 11:56:37

我认为您最好在这里提问 https://groups.google.com/论坛/#!forum/limejs
请检查以下事项:

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

I think you'd better to ask your question here https://groups.google.com/forum/#!forum/limejs
Please check the following things:

  • If all the spritesheet items referenced in KeyframeAnimation are present in your spritesheet
  • Try to use setDelay, setLooping API methods instead of direct assignment
  • I do not see monster variable definition...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文