CraftyJS: can a custom HitBox be used with the Gravity component?

43 views Asked by At

Using CraftyJS to create a 2D platformer, when a character's feet are narrower than the full sprite width can a custom hitbox be applied that is then honored by the "Gravity" component? It appears the full width of the component is supported even when a smaller hitbox is applied.

Here's an example where WiredHitBox illustrates that the element's custom hitbox is not interacting with the floor's hitbox, it is still supported.

enter image description here

Below is the example code I'm trying. Is there any way to have the Gravity component honor the custom hitbox? Or, maybe I'm thinking of this the wrong way and should be approaching this differently.

<html>
  <head></head>
  <body>
    <div id="game"></div>
    <script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script>
    <script>
      Crafty.init(640,480, document.getElementById('game'));

      Crafty.e('2D, Canvas, Color, Twoway, Gravity, Collision, WiredHitBox')
        .attr({x: 320, y: 0, w: 50, h: 50})
        .twoway(200, 480)
        .collision([10, 40, 40, 40, 40, 50, 10, 50])
        .gravity('Floor')
        .gravityConst('900')
        .color('#888888');

      Crafty.e('2D, Canvas, Color, Floor, Collision, WiredHitBox')
        .attr({x: 0, y: 470, w: 640, h: 10})
        .color('#5555ff');

     Crafty.e('2D, Canvas, Color, Floor, Collision, WiredHitBox')
        .attr({x: 320, y: 400, w: 320, h: 10})
        .color('#5555ff');



    </script>
  </body>
</html>

0

There are 0 answers