我看到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