Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity.setHitbox and Entity.mask are different #610

Open
XANOZOID opened this issue Dec 18, 2018 · 0 comments
Open

Entity.setHitbox and Entity.mask are different #610

XANOZOID opened this issue Dec 18, 2018 · 0 comments

Comments

@XANOZOID
Copy link
Member

XANOZOID commented Dec 18, 2018

  • HaxePunk version: 4.1.0
  • Target(s): Neko
  • Haxe version: 3.4.7
  • NME version: 6.0.58

When setting the hitbox (mask) for an entity it seems that the built in function for setHitbox is doing some things incorrectly; at least this is what the results are showing. The results are specifically different when we are using origins other than 0 I believe.

The code below will demonstrate this visually. One box will be using Entity.setHitbox while the other box will use Entity.mask = new Hitbox() using the same values.

(make sure to display masks using the console)

package scenes;

import haxepunk.Scene;
import haxepunk.Entity;
import haxepunk.debug.Console;
import haxepunk.graphics.Image;
import haxepunk.utils.Color;
import haxepunk.masks.Hitbox;

class GarbageScene extends Scene {


    public var mouse:Entity;

    override public function begin() {
        
        if( !Console.enabled ){ Console.enable(); }

        var bad = createEntity( 200, 200, Color.White );
        bad.setHitbox( 32, 32, -40, -40 );

        createEntity( 280, 280, Color.Black );

        mouse = createEntity( 0, 0, Color.getColorRGB(0,255,0) );
        
    }

    override public function update(){

        mouse.moveTo( mouseX, mouseY );
        mouse.graphic.color = Color.getColorRGB( 0, 255, 0 );
        if( mouse.collide( "box", mouseX, mouseY ) != null ){
            mouse.graphic.color = Color.getColorRGB( 0, 0, 255 );
        }

        super.update();
    }

    private inline function createEntity( x:Int, y:Int, color:Color, type:String="box" ):Entity{
        var e = new Entity( x, y );
        e.graphic = Image.createRect( 32, 32, color );
        e.graphic.centerOrigin();
        e.type = type;
        e.mask = new Hitbox( 32, 32, -40, -40 );
        add( e );
        return e;
    }

}

Results:

image

@XANOZOID XANOZOID changed the title Entity.setHitbox vs Entity.mask is different Entity.setHitbox and Entity.mask are different Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant