Chendler Posted August 22, 2014 Share Posted August 22, 2014 Hello, community. Now I'm finding the best way for squat action for my game creature.Sprite has fixed height, for example 500px. But player in squat state should have 300px height. How to teach him squatting? Thank you. Link to comment Share on other sites More sharing options...
Chendler Posted August 26, 2014 Author Share Posted August 26, 2014 Does anybody know the solution? Link to comment Share on other sites More sharing options...
j0hnskot Posted August 26, 2014 Share Posted August 26, 2014 I dont think i understood what you are asking. Do you want to reduce the height of the sprite? change it by sprite.height. Do you want to make your character crouch? You must use a texture that shows him crouching, or an animation. Link to comment Share on other sites More sharing options...
oxysoft Posted August 26, 2014 Share Posted August 26, 2014 Add a crouch sprite to your character's spritesheet and adjust the sprite's bounding box with body.setSize(...) whenever the entity is crouching Link to comment Share on other sites More sharing options...
Chendler Posted August 27, 2014 Author Share Posted August 27, 2014 I dont think i understood what you are asking. Do you want to reduce the height of the sprite? change it by sprite.height. Do you want to make your character crouch? You must use a texture that shows him crouching, or an animation. Add a crouch sprite to your character's spritesheet and adjust the sprite's bounding box with body.setSize(...) whenever the entity is crouching Thanks guys.I forgot about this topic. But oxysoft's is right, I used setSize() method for reduce bounding box. Thanks. Link to comment Share on other sites More sharing options...
Chendler Posted August 28, 2014 Author Share Posted August 28, 2014 Oh, I didn't solve this issue. If I change sprite height by setSize or manually by height property it cuts my height from bottom, then when I restore height - height adds from bottom and my hero falls under the ground. Link to comment Share on other sites More sharing options...
Nepoxx Posted August 28, 2014 Share Posted August 28, 2014 I'm not entirely sure, but I think your anchor point is going to determine where your sprite is scaled from/to. Link to comment Share on other sites More sharing options...
Chendler Posted August 28, 2014 Author Share Posted August 28, 2014 (edited) I'm not entirely sure, but I think your anchor point is going to determine where your sprite is scaled from/to. If I just scale sprite - it will be ugly. I need something such as http://jsfiddle.net/2e77q54s/19/ but without falling I've just tried set scale:- it's ugly- after scale restoring hero falls under the ground layer Edited August 28, 2014 by Chendler Link to comment Share on other sites More sharing options...
Chendler Posted August 28, 2014 Author Share Posted August 28, 2014 I found nice solution.playerDuck: function() { if (player.body.touching.down && !player._inDuck) { player._verticalPosition = player.y; player._normalHeight = player.height; player._inDuck = true; player.body.height = 0.75 * player._normalHeight; player.y = player.y + player._normalHeight - player.body.height; player.frame = 5; } }, playerUp: function() { if (player.body.touching.down && player._inDuck) { player._inDuck = false; player.body.height = player._normalHeight; player.y = player._verticalPosition; player.frame = 2; } }It works for me. Link to comment Share on other sites More sharing options...
Recommended Posts