At 4/5/20 07:22 PM, catproX wrote:
My apologies for asking a lot of questions, but I'm new to haxeflixel.
No worries, I'm happy to help!
Is there a way to set the size of the collision box? It seems like much of the characters graphical space and the hit box are one in the same. I did see a method for updating the hitbox if you scale the sprite, but that seems different than having a hitbox smaller than the view-able graphical area.
If this is not the case, I may have to rethink and simplify my character composition and keep it in a more defined "squared" space.
For example, I've been playing around with this gun-toting-plague-doctor character that I've created for the game jam.
But the collision doesn't seem to line up properly with the hand drawn frames within the sprite. In Godot, I would set a collision shape (such as a capsule) and align it center of the sprite. Extra graphical bits, like the gun, wouldn't count regarding collision.
When a FlxSprite's graphic/animation is changed it automatically sets the hitbox to that graphics frame size. you can override this by editing the width, height and offset properties. For example, if you loaded in a 32x32 graphic but want a 16x16 hitbox aligned to the bottom-center of the graphic you would do:
sprite.width = 16;
sprite.height = 16;
sprite.offset.set(8,16);
// alternatively:
// sprite.offset.x = 8;
// sprite.offset.y = 16;
and while flixel is very heavily geared towards square hitboxes (in fact, it doesn't have other shapes available out-of-box), this is surprisingly less limiting than one would think for most action games. Yes, you may need to fit your graphic to a more sqaure-ish shape, but there are other options.
You can specify a notify callback and process callback to FlxG.overlap to perform advanced checks, like if you want something to be a circle, you can do
FlxG.overlap(myCircle, circleKillerGroup,
function circleNotifyCallback(circle:FlxSprite, killer:FlxSprite):Void
{
trace('$circle hit $killer');
},
function circleProcessCallback(circle:FlxSprite, killer:FlxSprite):Bool
{
var cRad = circle.width / 2;
var kRad = killer.width / 2;
var distance = FlxVector.get(circle.x, circle.y).subtract(killer.x, killer.y);
var distanceSqruared = distance.lengthSqaured;
distanceV.put();
return distanceSqruared < cRad*cRad + kRad*kRad;
}
);
Aditionally you use multiple hitboxes per object. often I'll set my player's sprite's hitbox for level collision but give it's class FlxObject properties like attackBox and hurtBox and use them via:
if (player.attacking)
FlxG.overlap(player.attack, attackableGroup, onPunchEnemy);
you can have as many hitboxes per sprite as you feel
I'm also fairly new to TexturePacker, I might be missing something in the spritesheet/atlas publish settings.
I just use uniformly spaced spritesheets, because I think it's beneficial to the player to have blocky sprites with matching hitboxes
Edit: didn't realize Flixel could use non-uniform spritesheet's. i've removed the bottom of this post where I say otherwise