小编0x0*_*x01的帖子

如何在Javascript(没有画布)中平滑移动角色

我正在努力为我正在努力开发的js游戏中的角色制作动画.我不能使用画布,所以它只是DIV.使用当前的功能,我可以向左/向右移动我的角色,但它根本不是平滑的,它是一种"一步一步".我一直在寻找答案,但我发现的唯一解决方案是使用画布.

这是我的代码(全屏效果更好,但有点位置):

function avancerRight()
{
	var batman=document.getElementById("batman");
	x=batman.style.left;
	
		batman.className="dirDroite";
		batman.style.left=parseInt(x)+10+"px";

	return false;
}

function avancerLeft()
{
	console.log("dedede");
	var batman=document.getElementById("batman");
	x=batman.style.left;
	
		batman.className="dirGauche";
		batman.style.left=parseInt(x)-10+"px";

	return false;
}



var jumpHeight = 200;
var jumping = false;
function jump() {
                        
  if (!jumping) {
    jumping = true;
    setTimeout(land, 500);
  }

  if (jumping) {
    y=batman.style.top;

		batman.style.top=parseInt(y)-jumpHeight+"px";
  }
}

function land()
{
	jumping=false;

	y=batman.style.top;

	batman.style.top=parseInt(y)+jumpHeight+"px";
}
Run Code Online (Sandbox Code Playgroud)
body {
	padding: 0;
	margin: 0;
	background: url('http://image.noelshack.com/fichiers/2015/16/1428996568-bg.png');
	background-color: #B4381F;
	background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: 100%;
    background-position: 50% 30%; 

}

#batman{ …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery html5

5
推荐指数
1
解决办法
1335
查看次数

标签 统计

css ×1

html ×1

html5 ×1

javascript ×1

jquery ×1