Jump to content

Help me understand Groups


Draconar
 Share

Recommended Posts

I'm still trying to figure out exactly how to use groups and what they are good for.

 

In the documentation, it says that "transformations are applied to the group as whole", etc. When I read this, it seems that the group as whole are treated the same way, but what about a group of enemies in a space invaders clone? Every enemy has its own position, life/dead state, etc.

 

I'm working in a sports game, and the logical groups would be:

 

- player's team

- computer's team

- ball 

- ball + any of the team's members

 

but if the group is a single logical entity, how will I be able to give each team's member it's ai and how would I get a member to become a group "member + ball"?

 

 

Link to comment
Share on other sites

You're understanding it just right. You can both use groups as a good way to organize a bunch of logically related display objects (all your enemy sprites, all the obstacles in a level) *AND* as a single logical entity (e.g. every Sprite is also a Group and can have children).

 

This lets you use the group as a whole for running physics collisions/overlaps which is super common.

 

You could also add children to your player's sprite representing different weapons or hats, though, and their position will be relative to the sprite's anchor. For example, your player sprite's anchor is (0.5, 1) and it is 16x16. You want to add a hat with an anchor of (0.5, 0.5). Add the hat at (0, -16) to add it to the top of the parent. The hat will always be positioned relative to its parent's position (the player).

 

One thing, though: display objects can only belong to one group at a time, accessible via their "parent" property. If they are not added to a group they will be in the physics world accessible as "game.world".

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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