이것이 작동하지 않는 이유를 알 수없는 것 같습니다.Uncaught TyperError, 프로토 타입을 처음 사용하는 경우
줄 'this.Sprite_initalize (playerSpriteSheet);' 'Uncaught TypeError : undefined is not a function.'오류가 발생했습니다. 프로토 타입을 올바르게 사용하고 있습니까?
function init() {
canvas = document.getElementById("canvas");
// Creates the stage
stage = new createjs.Stage(canvas);
// Loads the image for player
imgPlayer.src = "img/player.png";
// Create player and add to stage
player = new Player(imgPlayer,300);
stage.addChild(player);
}
function Player(imgPlayer, x_start,x_end){
this.initialize(imgPlayer,x_start,x_end);
}
Player.prototype = new createjs.Sprite();
Player.prototype.alive = true;
// constructor
Player.prototype.Sprite_initialize = Player.prototype.initialize; //avoid overiding base class
Player.prototype.initialize = function (imgPlayer,x_end){
var playerSpriteSheet = new createjs.SpriteSheet({
// Sprite sheet stuff
images: [imgPlayer],
frames: [
[0,0,26,26], //beginWalk0
[26,0,26,26], //walk0
[52,0,26,26], //walk1
[78,0,26,26], //walk2
[0,26,26,26], //stand0
[26,26,26,26], //stand1
[0,52,28,32], //jump0
],
animations: {
stand:{
frames:[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5],
speed:0.3
},
walk:{
frames:[1,2,3],
next:"walk",
speed:0.3
},
beginWalk:{
frames:[0],
next:"walk",
},
jump:{
frames:[6],
},
}
});
this.Sprite_initialize(playerSpriteSheet);
this.x_end = x_end;
// play stand sequence
//this.gotoAndPlay("stand");
this.isInIdleMode = true;
this.name = "Player";
// 1 = right & -1 = left
this.direction = 1;
}
시도를 'Player.prototype.initialize' 다음에'Player.prototype.Sprite_initialize = Player.prototype.initialize;'넣기 – jcubic