Jump to content

Need some ideas for a name for a new Game Object Group


rich
 Share

Recommended Posts

Hi all,

 

I've been working hard on the contents for the Phaser Book of Games (I'll write more about that next week), which strangely enough, has included making lots of games! and one thing I keep coming back to - and am therefore going to add into Phaser, is the need for a new different type of Group.

 

Groups are vital in any game, but because they inherit from the Pixi DisplayObjectContainer they're essentially display objects in their own right. Yet there is a real need for a Group that isn't part of the display list. For example when doing depth sorting in a scene you need to have all display objects in a single Group to be able to sort them based on their z-index: think Zelda where you can walk 'down' the screen and objects should appear behind and in front of you. But in order to do that currently all of those objects need to be in the same Group - which means you can't use all of the great features of Group like 'getFirstDead' because you might get any object back and then have to process it yourself in code.

 

So my thinking is that we need a new type of Group that doesn't extend a display object and isn't on the display list itself at all. You can add objects to it and then use methods like 'getRandom' or 'getValue' or 'find' or all manner of searching methods to interrogate the contents of the Group and retrieve them.

 

This would allow you to logically break your game objects up, in as many different ways as you wish, while doing so completely independently of the display list.

 

What I'm struggling with is what to call them though. In an ideal world I could rename Group to Layer, and then use Group for this. But I can't do that, as it will break every tutorial ever written for Phaser :)

 

I was thinking 'pool' - that is what they are on a technical level, but it doesn't sound right to me. Whatever word I use it has to be 'snappy' and easy to write without making a typo (i.e. "container" is quite easy to spell wrong)

 

So ... any ideas? :) (either for a name for this new thing or for any features you'd like it to have)

Link to comment
Share on other sites

Yes, collection sounds good.

What I thought of, there should be a class for creating particle reusable objects. What I mean by this is what you have to manually do when create bullets for a game:

- create a pool of X bullets, all invisible

- when you shoot a bullet, you take an unused one from the pool

- kill the bullet if it is destroyed or exits screen.

This is usually done to avoid memory leaks and reuses objects instead of deleting/instantiating them.

So, the API would be something like this:

var bullets = new Phaser.Pool(sprite, 100); // instantiate 100x sprite

var myBullet = pool.get(); // returns one unused item for the pool

pool.release(obj); // kills it or make it invisible, also marks it as unused

Here, sprite could either be an instance Sprite or any object class than can be instantiated.

This Pool class could extend the Collection class.

I am on my tablet and probably most of the stuff I've written here makes no sense, but I hope you understood my idea.

I know that you can already do this using Groups, but having a simpler way to create re-usable objects would be nice.

Link to comment
Share on other sites

I honestly think I'd actually prefer it if you renamed groups to layers and called the new thing a group, mostly because it would be the most accurate description of what's inside. But then again I haven't published any tutorials. :) What if you did a two step process where you vacated the Group moniker while you renamed the old Group to Layer, and only introduced the new Group in a later update?

 

Maybe throw a little skeleton Group in there in the intermediate that does nothing but put out an alert "please use Layers"

Link to comment
Share on other sites

Nah it's absolute not going to turn into an ECS!

 

I'm thinking Pool might be it. But I do like List too. Technically though it will be more like a Set (from a data structure pov) but it will have so many extra bits it won't be a traditional one either.

Link to comment
Share on other sites

You can add objects to it and then use methods like 'getRandom' or 'getValue' or 'find' or all manner of searching methods to interrogate the contents of the Group and retrieve them.

Could you not just use ordinary arrays and add a few custom convenience methods for working them?

Link to comment
Share on other sites

"Pool" seems like it would automatically implement recycling, as that's generally where I've heard the term.

 

If it doesn't then maybe something else.

 

How about these suggestions:

* Assembly

* Bag

* Cartel

* Lot

* Store

* Batch

* Cluster

* Crowd

* Stack

* Heap

* Pile

* Kit

 

I, personally, like "Stack", as it has a double meaning referencing an actual layered memory stack (which is, by definition, not a display element) as well as describing the exact function (stacking) that you're trying to implement.

Link to comment
Share on other sites

"Pool" seems like it would automatically implement recycling, as that's generally where I've heard the term.

 

If it doesn't then maybe something else.

 

How about these suggestions:

* Assembly

* Bag

* Cartel

* Lot

* Store

* Batch

* Cluster

* Crowd

* Stack

* Heap

* Pile

* Kit

 

I, personally, like "Stack", as it has a double meaning referencing an actual layered memory stack (which is, by definition, not a display element) as well as describing the exact function (stacking) that you're trying to implement.

 

The problem with Stack, is that you usually think to the stack data structures (with it's push and pop methods)

Link to comment
Share on other sites

I like stack, but this sounds like it would be ordered. Collection also.

But on a side note, would this new object allow grouping audio? Or does this feature exist, I'm currently trying to implement a FX sound volume setting and a background sound setting and it would be awesome to group them.

Link to comment
Share on other sites

I'd go with Pool. Yeah, it maybe implies a few more semantics than you're talking about including, but I don't think it's so much as to be misleading. In any event, I think that having separate objects for display grouping and logical grouping is A Good Thing.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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