I made a new class (HitBox) and an accompanying Actor behavior that lets me add them. I attached a couple of screenshots: the manager behavior and example usage for the player's punch attack. I haven't done anything too elaborate with it yet. In the example attack, the hitbox manager returns the name of the hitbox that was hit. I have this set up to only report a hit in one box at one moment in time, but it wouldn't be difficult to expand it to check for multiple hit boxes across multiple frames.
This setup is completely independent from the standard collision boxes. You can see in my example usage I just loop through all of the actors on screen and check if the player's attack point is inside any of the actor's hitboxes (those that have them, anyway).
/*
Stencyl exclusively uses the Haxe programming language.
Haxe is similar to ActionScript and JavaScript.
Want to use native code or make something reusable? Use the Extensions Framework instead.
http://www.stencyl.com/help/view/engine-extensions/
Learn more about Haxe and our APIs
http://www.stencyl.com/help/view/haxe/
*/
package scripts;
import com.stencyl.Engine;
class HitBox
{
public var name:String;
public var x0:Float;
public var y0:Float;
public var x2:Float;
public var y2:Float;
public var body_width:Float;
public var body_height:Float;
public function new( n:String, a:Float, b:Float, c:Float, d:Float, e:Float, f:Float )
{
this.name = n;
this.x0 = a;
this.y0 = b;
this.x2 = c;
this.y2 = d;
this.body_width = e;
this.body_height = f;
}
public function point_in_box( local_x:Float, local_y:Float, ?right:Bool = true )
{
if ( right )
return local_x >= x0 && local_x <= x2 && local_y >= y0 && local_y <= y2;
else
return local_x >= ( body_width - x2 ) && local_x <= ( body_width - x0 ) && local_y >= y0 && local_y <= y2;
}
public function box_in_box( hit_x:Float, hit_y:Float, hit_w:Float, hit_h:Float, right:Bool = true )
{
var hit_x0:Float, hit_x2:Float, hit_y0:Float, hit_y2:Float;
hit_x0 = hit_x;
hit_x2 = hit_x + hit_w;
hit_y0 = hit_y;
hit_y2 = hit_y + hit_h;
if ( right )
return VUtility.AABBOverlap( hit_x0, hit_y0, hit_x2, hit_y2, x0, y0, x2, y2 );
else
return VUtility.AABBOverlap( hit_x0, hit_y0, hit_x2, hit_y2, body_width - x2, y0, body_width - x0, y2 );
}
public function sided_x0( ?right:Bool = true ):Float
{
if ( right )
return x0;
else
return body_width - x2;
}
public function sided_x2( ?right:Bool = true ):Float
{
if ( right )
return x2;
else
return body_width - x0;
}
}