Open lawalm opened 7 years ago
Is the console.log
message "spacebar pressed" displaying?
Yes, it does. Thanks for your assistance.
On Wed, Jul 13, 2016 at 5:43 PM, kittykatattack notifications@github.com wrote:
Is the console.log message "spacebar pressed" displaying?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kittykatattack/hexi/issues/13#issuecomment-232414397, or mute the thread https://github.com/notifications/unsubscribe/ALP51n0titwFaeVpYEk_ptf4setufYmmks5qVRWpgaJpZM4JLPk4 .
Hello, The sprite object is not responding to 'spaceBar' being pressed(the sprite doesn't jump). See code below, I can't figure out the coding error.
function setup() { dungeon = g.sprite('assets/dungeon.png');
platform = g.sprite('assets/platform.png'); platform.x = 25; platform.y = 330;
cat = g.sprite('assets/cat.png'); cat.accelerationX = 0; cat.accelerationY = 0; cat.frictionX = 1; cat.frictionY = 1; cat.gravity = 0.3; cat.jumpForce = -6.8; cat.vx = 0; cat.vy = 0; cat.isOnGround = true;
let leftArrow = g.keyboard(37), rightArrow = g.keyboard(39), spaceBar = g.keyboard(32);
//Left arrow key leftArrow.press = () => { if (rightArrow.isUp) { cat.accelerationX = -0.2; } }; leftArrow.release = () => { if (rightArrow.isUp) { cat.accelerationX = 0; } }; //Right arrow key rightArrow.press = () => { if (leftArrow.isUp) { cat.accelerationX = 0.2; } }; rightArrow.release = () => { if (leftArrow.isUp) { cat.accelerationX = 0; } }; //Space key (jump) spaceBar.press = () => { console.log('spacebar pressed') // if (cat.isOnGround) { cat.vy += cat.jumpForce; cat.isOnGround = false; cat.frictionX = 1; } //};
//Change the state to
play
g.state = play;} function play() { if(cat.isOnGround) { cat.frictionX = 0.92; } else { cat.frictionY = 0.97; }
// cat.jumpForce = -0.5;
}
Regards and thanks marlene. p.s Will put folder in dropbox.