Best way to Create "Groups"


(Secretmapper) #1

How can I have ‘groups’ in flashpunk? Just like the graphic list but for entities? (And/Or Multiple Worlds?)


(Jonathan Stoler) #2

I’m not sure exactly what you want this for, but for simple things, just use a Vector:

var entityList:Vector.<Entity> = new Vector.<Entity>();

// add to the vector
entityList.push(new Entity());

If you want to do more complex things with this, I would recommend creating your own class, EntityList, that has an internal Vector to store Entities but can perform operations on those entities (if I’m not mistaken this is exactly what a Graphiclist does).


(Secretmapper) #3

I was looking more into making the coordinates inherit from it’s parent, so that when I move the ‘container’ entity, all entities move with it.


(Jonathan Stoler) #4

There’s probably a better way to do this, but off the top of my head, you could do something like this in an EntityList object (assuming entities is a Vector full of Entity objects).

public function set x(newX:Number){
	var xDiff:Number = newX - this.x;

	for(var i:uint = 0; i < entities.length; i++){
		entities[i].moveBy(xDiff, 0);
	}
}

Of course, you can do the same for y.


(Zachary Lewis) #5

You’re looking for FP.anchorTo().