Regenuluz Posted May 1, 2014 Share Posted May 1, 2014 Hey guys, So I'm using Pixi.js for my bachelor project to create a game that can assist kids in learning number sequences, and it has been working out great so far. However, I'm now at a stage we're I'd like my player entity to actually be animated, instead of it just being a static PIXI.Sprite that moved around on the screen. Thus I turned to Spine seeing that Pixi.js has support for it and it took a full blown 5 minutes or so to get Spineboy to render and animate in my game. So I thought, that's awesome, I'll just go and fix it up like my new player object, which looks like this:function Player(x, y, origTexture) { // Get texture var texture = PIXI.Texture.fromImage(origTexture); // Initialize PIXI.Sprite.call(this, texture, texture.frame.width, texture.frame.height); // Set anchor and pivot points this.anchor = new PIXI.Point(0.5, 0.5); this.pivot = new PIXI.Point(0.5, 0.5);}Player.constructor = Player;Player.prototype = Object.create(PIXI.Sprite.prototype);Player.prototype.update = function() { // [Snip...]};Player.prototype.hit = function() {};Player.prototype.pickup = function() {};Player.prototype.alive = function() {};So I hurried up and crafted the following little code snippetfunction newPlayer(animation) { PIXI.Spine.call(this, animation); this.position = new PIXI.Point(100, 100);}newPlayer.constructor = newPlayer;newPlayer.prototype = Object.create(PIXI.Spine.prototype);Then I tried to create a new player objectvar player = new newPlayer('spineboy.anim');Aaaand stuff broke, giving me the following error "TypeError: 'undefined' is not a function (evaluating 'this.addChild(g)')" So my question is, is it possible to do what I'm trying to do? And is it even the 'correct' way of doing it? Cheers! (Oh, and I am using version 1.5.3 of Pixi.js.) Quote Link to comment Share on other sites More sharing options...
Regenuluz Posted May 2, 2014 Author Share Posted May 2, 2014 Well, nevermind. I figured it out. Turned out I was misplacing the constructor.function Player(x, y, animation) { PIXI.Spine.call(this, animation); // Set anchor and pivot points this.anchor = new PIXI.Point(0.5, 0.5); this.pivot = new PIXI.Point(0.5, 0.5);}Player.prototype = Object.create(PIXI.Spine.prototype);Player.prototype.constructor = Player;And it works as it should. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.