6
« on: September 16, 2015, 06:06:42 pm »
I'm trying to implement a region that I can place and size in the scene editor, so that when my player enters it he gets blown upwards. This is the code - it creates a region that overlaps with the actor representing the region, and then hides the actor.
In the Updated event, I iterate over all the actors inside the region, and apply a force to them. This can be used to implement windy areas in the level, and those areas can be turned on and off. Pretty neat.
Except that it doesn't work. Once the actor enters the region, getActorsInRegion() continues to return that actor even after it gets blown out of the region.
What's going on here?
I'm attaching the code block images, if they're easier for some people to read.
override public function init()
{
/* ======================== When Creating ========================= */
createBoxRegion(ScaleUtils.scaledCoord("x", actor), ScaleUtils.scaledCoord("y", actor), ScaleUtils.scaledSize("width", actor), ScaleUtils.scaledSize("height", actor));
trace("Region creatd at (" + ScaleUtils.scaledCoord("x", actor) + ", " + ScaleUtils.scaledCoord("y", actor) + ", " + ScaleUtils.scaledSize("width", actor) + ", " + ScaleUtils.scaledSize("height", actor)+")");
_Region = getLastCreatedRegion();
propertyChanged("_Region", _Region);
actor.disableActorDrawing();
/* ======================== When Updating ========================= */
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
if(wrapper.enabled)
{
for(actorInRegion in getActorsInRegion(_Region))
{
if(actorInRegion != null && !actorInRegion.dead){
if(!(actorInRegion == actor))
{
trace("" + actorInRegion);
actorInRegion.push(_X, _Y, _ForceMagnitude);
}
}
}
}
});
}