Sign in to follow this  
ptotheaul

TypeError: this.game.add is not a function

Recommended Posts

I'm trying to use a dragon bones plug in (https://github.com/raksa/phaser-dragonbones#need-help)

The example is using a single state and to add the character to the game this is used:

var sprite = this.dragonBonesPlugin.getArmature("key");
this.world.add(sprite);

 

I'm trying to empliment this in a state system where my game is defined with the game variable passed in:

var theGame = function(game){  etc.

Adding normal sprites works like this:

this.screenshot = this.game.add.sprite(0, 0, 'ss');

But for some reason trying to add the dragon bones animation like this:

this.character = this.dragonBonesPlugin.getArmature('key')
this.game.add(this.character);

is giving me this error 'TypeError: this.game.add is not a function'

Does anyone know what the issue could be?  I found this forum which sounds like it has kind of the same issue:

I've tried some of the solutions mentioned(like adding 'use strict') but nothing has worked.  Any clues?

 

Here is a screen shot of the error info.  Could it have something to do with the loading?

 

image.thumb.png.4e8e8773f0a892e04ed78d9da3af230c.png

 

 

 

 

Share this post


Link to post
Share on other sites

game.add is indeed not a function. It's a reference to GameObjectFactory, which itself has methods like .sprite(), .group() and, as gauravD mentioned, .existing(), which is great when you have to add a generic GameObject.

Share this post


Link to post
Share on other sites

can you provide the code where you make the dragon bones armature and then retrieve it back? I am not sure from your error log where the original break happened, because it doesn't even go into the dragon bones plugin. getarmature expects a root armaturename, so if that is not set, it could cause the issue. if you don't provide enough code to compare against the plugin, then it might not be possible to troubleshoot your issue. try to console.log the sprite before adding it to the game and see what that brings up.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.