Author Topic: Suggestion: Regions for FlxSprites  (Read 1575 times)

bepawuca

  • Guest
Suggestion: Regions for FlxSprites
« on: Sun, Dec 13, 2009 »
What I mean is that you could limit the possible position of an FlxSprite to a certain region, like this:

// In the FlxSprite.update() function

if (hasRegionLimits)
{
  if (region.boundaryShape == "Rectangle")
  {
    if (x - offset.x < region.upperLeft.x)
    {
      x = region.upperLeft.x + offset.x;
    }
    if (x + width - offset.x > region.lowerRight.x)
    {
      x = region.upperLeft.x + width - offset.x;
    }
    if (y - offset.y < region.upperLeft.y)
    {
      y = region.uppderLeft.y + offset.y;
    }
    if (y + height - offset.y > region.lowerRight.y)
    {
      y = region.upperLeft.y + height - offset.y;
    }
  }
  else if (region.boundaryShape == "Circle")
  {
    var pos:Point = new Point(x, y);
    if Point.distance(pos, region.center)
    {
      pos = region.center.add(pos.subtract(region.center)).normalize(region.radius);
    }
  }
}

Or something like that. It would come in handy; with every update of flixel I've used so far, I've had to implement a simple version of region limitation.
Could you please add this to the next update?

fefranca

  • Guest
Re: Suggestion: Regions for FlxSprites
« Reply #1 on: Wed, Dec 16, 2009 »
Create a class that extends FlxSprite.. should make your life a lot easier!

bepawuca

  • Guest
Re: Suggestion: Regions for FlxSprites
« Reply #2 on: Thu, Dec 17, 2009 »
Yeah, I'm actually working on one right now.