Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Grouping Confusion


silversteez
 Share

Recommended Posts

Hey all,


 


I’m new to Phaser and have been trying to figure something out. I’m trying to bundle a few sprites and bits of text into a group (say, to make a dynamically generated ‘card’ for a card game like MTG), but I’m running into a number of headaches because groups…well, they don’t work quite the way I expected them to, I guess.


 


Groups don’t seem to have a lot of the convenience methods that sprites have, for example. Dragging a group as a unit (my ‘card’ described above) seems to require custom code which, while totally fine, just surprised me. Seems like it would be nice to have a ‘group’ or empty ‘gameObject’ that could have a collider and then just add sprites and text to that. Then I’d have all of the nice things that sprites have like events and dragging, etc. Just feels like I have to do quite a bit of trickery from the get-go to get my grouped object to work nicely.


 


Not trying to poopoo on groups - I can see that they offer a lot of benefits in their current implementation - for sorting, collisions, etc. It seems like they weren’t really built with the intention of behaving like I thought they ought to. I guess I’m just wondering if I’m approaching this wrong or missing something? Has anyone come up with a good way to achieve what I’m describing above with my ‘card’ combo-group-object thing?


 


Thanks very much!


 


- Matt


Link to comment
Share on other sites

For dragging things around as a single card, you can have the base of the card as a Phaser.Sprite, and add the images and text to that using the addChild function.

Then you just do all the input handling on the base sprite, and the rest moves with it.

Link to comment
Share on other sites

Wow, thanks! I've looked at a bunch of tutorials and the official examples, searched through the docs and this forum, and this is the first I've heard of this.

 

Looks like it's pretty deep down the prototype chain. Do you think this method is officially supported by Phaser or is this something that just happened to come along with Pixi and might break in future engine updates? 

Link to comment
Share on other sites

For dragging things around as a single card, you can have the base of the card as a Phaser.Sprite, and add the images and text to that using the addChild function.

Then you just do all the input handling on the base sprite, and the rest moves with it.

 

I can't seem to find any sort of addChild in Phaser 1.1.6, let alone for the Sprite class. Is this a 1.2 thing only?

Link to comment
Share on other sites

It's definitely present on 1.1.4 (just checked the breakout example game at examples.phaser.io - open the console, start typing 'paddle.addChild', and it should autocomplete for you).

 

You guys might not be finding it because the addChild method isn't on any Phaser classes - it's actually on one of the lower level Pixi classes that Phaser.Sprite inherits from.

 

That's why I'm wondering if there will be problems using it down the line.

Link to comment
Share on other sites

Hmmm I see... I was able to find it using the 1.1.6 version of Phaser using your method.

However because the phaser.d.ts file does not have an addChild() method, the tsc node command fails to compile the game. 

 

Does anyone know if there is a suitable workaround for this?

 

Obviously I could just add to the phaser.d.ts file, but then it would be overridden when I update Phaser.

 

So, I tried adding a new .d.ts file, but it seems the tsc compiler only listens to one .d.ts file if they reference the same class/module.

 

ie: 

define module Phaser 

is only picked up once, and not merged, which makes sense.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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