Jump to content

Extending PIXI.Spine?


Regenuluz
 Share

Recommended Posts

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 snippet

function 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 object

var 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.)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...