Adjust the angle of a hitbox?


(Nate ) #1

Hey guys! So I have a character, and he is able to change his angle when jumping in the air to a max of either 60 or -60. When he touches the ground he goes back to 0. I was wondering if when his angle is changing there was a way I could also spin his hitbox to stay lined up with him?

Thank you!


(kgbkgb) #2

I have a solution that may work for you, It doesn’t involve rotating hit-boxes but this allows you to have pixel perfect collisions with animation. All you do is enable masks on your objects you want to have perfect pixel collision If you have animation through a spritemap you also add a small function inside your net.flashpunk.graphics.Image.as class.

This stuff would go into your objects you want to have ppc(pixel perfect collision) with a spritemap class.

 protected var spriteMapExample:Spritemap = new Spritemap(SPRITEMAP_EXAMPLE, width, height);
 protected var Example_Mask:Mask;
    public function ExamplePlayer() {
         Example_Mask = new Pixelmask(spriteMapExample.getBuffer());
         mask = Example_Mask;

Then add this inside the Image.as

    public function getBuffer():BitmapData {
			return _buffer;
}

If you don’t need the animation in your collisions, say a static image. Don’t add the function into the Image.as Just use the above code with an Image and not a spritemap!

 protected var imageExample:Image = new Image(SPRITE_EXAMPLE);
 protected var Example_Mask:Mask;
        public function ExamplePlayer() {
             Example_Mask = new Pixelmask(imageExample);
             mask = Example_Mask;

Hope this helps/isn’t totally ignorant.


(Nate ) #3

Okay I will consider this solution. For now it is not an issue, but I can see it becoming an issue and if it does I would like a solution.

Thanks again!


(John Andersson) #4

I did this, but the collision detection doesn’t work… If I use the console I can see a sort of gray ghost of the entity, that is detecting the collisions, but not the visual graphic!