我看到Easeljs有两个不同的教程,一个是David Rousset,一个是Lee Brimelow。我不确定哪个更好用,什么区别。例1(大卫·鲁塞):Easeljs模式 - 解释差异
(function (window) {
function Player(imgPlayer, x_start, x_end) {
this.initialize(imgPlayer, x_start, x_end);
}
Player.prototype = new createjs.BitmapAnimation();
// public properties:
Player.prototype.alive = true;
// constructor:
Player.prototype.BitmapAnimation_initialize = Player.prototype.initialize; //unique to avoid overiding base class
var quaterFrameSize;
Player.prototype.initialize = function (imgPlayer, x_end) {
var localSpriteSheet = new createjs.SpriteSheet({
images: [imgPlayer], //image to use
frames: { width:64, height:64, regX:32, regY: 32 },
animations: {
walk: [0, 9, "walk", 4]
}
});
createjs.SpriteSheetUtils.addFlippedFrames(localSpriteSheet, true, false, false);
this.BitmapAnimation_initialize(localSpriteSheet);
this.x_end = x_end;
quaterFrameSize = this.spriteSheet.getFrame(0).rect.width/4;
// start playing the first sequence:
this.gotoAndPlay("idle"); //animate
this.isInIdleMode = true;
}
Player.prototype.tick = function() {
//specific tick function for the player
}
window.Player = Player;
} (window));
和例2(李布赖姆洛):
(function(window) {
function Player(){
// Adding the easeljs bitmap as a property of Player:
this.view = new createjs.Bitmap("assets/pics/player1.png")
// Setting som local parameters
var height = stage.canvas.height;
var width = stage.canvas.width;
var playerRadius = 70;
var offset = 200;
var x = 0;
var y = 0;
this.view.regX = this.view.regY = playerRadius;
// Adding the tickfunction below
this.view.onTick = tick;
}
function tick(e) {
//
}
window.Player = Player;
})(window);
只是ingnore一个使用BitmapAnimation和一个只是一个基本的位图。
在例1:
1)难道是更换线路相同的:这是什么的
this.alive = true;
2):
Player.prototype.BitmapAnimation_initialize = Player.prototype.initialize; //unique to avoid overiding base class
Player.prototype.alive = true;
与
做的,我不明白com换货......
3)这是行添加到启动用来初始化函数:
Player.prototype = new createjs.BitmapAnimation();
我不知道当新的播放器()例1中
4运行到底发生了什么)将tick设置为Player的属性将意味着您必须在主tick函数中调用此tick函数,使用easljs中Ticker类的内置onTick事件处理函数会更好吗(如示例2所示) ?
以上哪种模式是“最佳实践”,为什么?
此外,这两种模式都依赖于创建Player对象(并将Player对象设置为窗口属性)的main.js。为了保持全局范围内的所有内容或者能够将此代码用于例如node.js,最好将main.js包装在对象中,并且将此Main对象传递给一个参数的功能,而不是窗口?
比方说,你让这个主JS:
Main = {
init: function() {
//set up and create Player
var player = new Player;
},
//then adding som properties, variables to Main... for instance
propA: 0
}
这是可能的/ feasable?两个图案之间
这是个人喜好。选择一个你理解并喜欢的并且用它来运行。我投票结束,因为它太宽泛,主要是意见,而不是具体的事实来解答。 – WiredPrairie