正如我在标题中所述,easyljs对我来说是一个很新的东西,是否有任何方法可以通过使用框架Easeljs在我的画布中将单击事件或事件监听器添加到像spritesheet这样的对象中?

我已经做了很多研究,但仍然没有任何运气。

最佳答案

SpriteSheet只是描述如何绘制Sprite(或早期版本中的BitmapAnimation)的数据格式。

这是一个SpriteSheet示例,取自http://createjs.com/Demos/EaselJS/SpriteSheet.html的示例,您可以在GitHub存储库(github.com/CreateJS/EaselJS/)中找到该示例。

var data = new createjs.SpriteSheet({
    "images": ["images/sprite.png"],
    "frames": {"regX": 0, "height": 292, "count": 64, "regY": 0, "width": 165},
    "animations": {"run": [0, 25, "run", 1.5], "jump": [26, 63, "run"]}
});


一旦有了,就可以定义一个Sprite。

var sprite = new createjs.Sprite(data, "run");
stage.addChild(sprite);
// In earlier versions (0.6.0 and below), you can not specify a start frame/animation
sprite.gotoAndPlay("run");


这将把精灵添加到舞台上,并播放其“运行”动画。为了添加鼠标单击,请使用:

sprite.on("click", handleClickFunction);
// Earlier versions (0.6.0 and below) require the use of addEventListener, which still exists in 0.7.0, but is less friendly
sprite.addEventListener("click", handleClickFunction);


有关鼠标行为的更多信息,请参见EaselJS网站上的教程。
http://createjs.com/tutorials/Mouse%20Interaction/

关于javascript - 如何使用Easeljs将Click事件添加到spriteSheet?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19945106/

10-09 18:07