重力内html5画布 [英] gravity inside html5 canvas
问题描述
我试图做一个原始的超级马里奥游戏使用html5画布只是为了好玩,并了解更多关于画布工具和它的动画的副本,但我被困在使马里奥做这里的跳跃是我的jsfiddle: a href =http://jsfiddle.net/2tLCk/1/ =nofollow> http://jsfiddle.net/2tLCk/1/
I'm trying to do a copy of the original super mario game using html5 canvas just for fun and to learn more about the canvas tool and it's animation but i am stuck at making Mario do it's jump here is my jsfiddle : http://jsfiddle.net/2tLCk/1/
我应该如何解决我的向上
功能,使马里奥跳和回到地面像这个网站 http://博客。 nihilogic.dk /
我试图理解它的代码,但我不能?
how should i fix my up
function to make mario jump and return back to the ground like in this website http://blog.nihilogic.dk/
i tried to understand it's code but i couldn't ?
if (keydown.up) {
vy += gravity;
character.CurentPos = 11;
character.x += character.speed;
character.y += vy;
}
推荐答案
跳跃马里奥 http://jsfiddle.net/2tLCk/22/ 。
如果跳跃是1 - 向上。如果跳跃是2 - 向下。
If jumping is 1 - going up. If jumping is 2 - going down.
if(jumping){
if(jumping == 1) {
if(character.y > 140) character.y -= gravity;
else jumping = 2;
} else if(jumping == 2) {
if(character.y < 184) character.y += gravity;
else{
character.y = 184;
jumping = false;
character.CurentPos = 6;
}
}
}else if(keydown.up) {
jumping = 1;
character.CurentPos = 11;
}
您可能想使用 https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame 而不是setInterval()。
And you would probably want to use this https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame instead of setInterval().
这篇关于重力内html5画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!