- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在努力为我目前正在尝试开发的 js 游戏中的 Angular 色制作动画。我不能使用 Canvas ,所以它只是 DIV。使用当前功能,我可以向左/向右移动我的 Angular 色,但它一点也不流畅,有点“一步一步”。我一直在寻找答案,但我找到的唯一解决方案是使用 Canvas 。
这是我的代码(在全屏下效果更好,但位置有点问题):
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";
}
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{
background-image:url('http://image.noelshack.com/fichiers/2015/16/1428996568-batman.png');
width:85px;
height:85px;
display:block;
background-repeat: no-repeat;
position:absolute;
margin-top: -80px;
}
.dirDroite{
background-position: -95px 0px;
}
.dirGauche{
background-position: 0px 0px;
}
#fullbody {
margin: auto;
width: 100%;
height: 100%;
}
#floor {
position: absolute;
right: 0;
bottom: 0;
left: 0;
background: url("http://image.noelshack.com/fichiers/2015/16/1428996568-platform5.png");
background-repeat: repeat-x;
background-size: 100% 100%;
height: 126px;
}
#base {
position: absolute;
right: 0;
bottom: 80px;
left: 0;
z-index: 200;
margin: auto;
background: url('http://image.noelshack.com/fichiers/2015/16/1428996568-thefloor.png');
background-size: cover;
height: 70.56px;
width: 846.72px;
margin-top : 13.2vh;
}
#perspectiveGauche{
margin-top : 15vh;
-webkit-perspective: 4vh;
perspective: 4vh;
position: absolute;
width: 45vw;
perspective-origin: 50% 0%;
}
#rectangleHautGaucheH{
margin-left: 13.22vh;
width: 28.87vw;
height: 2vh;
background-color: #854305;
-webkit-transform: rotateX(2deg);
transform: rotateX(2deg);
}
#rectangleBasGaucheH{
width: 29.1vw;
margin-left: 13vh;
height: 3vh;
background-color: #663303;
}
#perspectiveGaucheBasse{
margin-top : 15vh;
-webkit-perspective: 0.1vh;
perspective: 0.1vw;
position: absolute;
width: 45vw;
perspective-origin: 50% 0%;
}
#rectangleHautGaucheB{
margin-top: 38vh;
margin-left: 28vh;
width: 15vw;
height: 0.25vh;
background-color: #854305;
-webkit-transform: rotateX(2deg);
transform: rotateX(2deg);
}
#rectangleBasGaucheB{
margin-top: 0.6vh;
width: 15.25vw;
margin-left: 27.75vh;
height: 3vh;
background-color: #663303;
}
#perspectiveDroite{
-webkit-perspective: 4vh;
perspective: 4wh;
position: absolute;
width: 39.6vw;
height: 2vh;
margin-top: 15vh;
perspective-origin: 200% 0%;
}
#rectangleHautDroitH{
margin-left: 125vh;
width: 28.7vw;
height: 2vh;
background-color: #854305;
-webkit-transform: rotateX(2deg);
transform: rotateX(2deg);
}
#rectangleBasDroitH{
width: 28.9vw;
margin-left: 124.8vh;
height: 3vh;
background-color: #663303;
}
#rectangleHautDroiteB{
margin-top: 37vh;
margin-left: 133vh;
width: 22vw;
height: 2vh;
background-color: #854305;
-webkit-transform: rotateX(2deg);
transform: rotateX(2deg);
}
#rectangleBasDroiteB{
margin-top: 0.2vh;
width: 22.18vw;
margin-left: 132.8vh;
height: 3vh;
background-color: #663303;
}
#perspectiveMilieu{
-webkit-perspective: 4vh;
perspective: 4wh;
position: absolute;
width: 39.6vw;
height: 2vh;
margin-top: 15vh;
perspective-origin: 130% 0%;
}
#rectangleHautMilieu{
margin-top: 21vh;
margin-left: 68.95vh;
width: 34.5vw;
height: 2vh;
background-color: #854305;
-webkit-transform: rotateX(2deg);
transform: rotateX(2deg);
}
#rectangleBasMilieu{
margin-top: 0.1vh;
width: 34.77vw;
margin-left: 68.7vh;
height: 3vh;
background-color: #663303;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LEVEL 1 NEGRILLON</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="scripts/script.js" ></script>
</head>
<body>
<div id="fullbody">
<div id="perspectiveGauche">
<div id="rectangleHautGaucheH"></div>
<div id="rectangleBasGaucheH"></div>
</div>
<div id="perspectiveGaucheBasse">
<div id="rectangleHautGaucheB"></div>
<div id="rectangleBasGaucheB"></div>
</div>
<div id="perspectiveDroite">
<div id="rectangleHautDroitH"></div>
<div id="rectangleBasDroitH"></div>
<div id="rectangleHautDroiteB"></div>
<div id="rectangleBasDroiteB"></div>
</div>
<div id="perspectiveMilieu">
<div id="rectangleHautMilieu"></div>
<div id="rectangleBasMilieu"></div>
</div>
<div id="base"></div>
<div id="floor"></div>
<!--<div id="platform1"></div>
<div id="platform5"></div>
<div id="floor">-->
<div id="batman" class="dirDroite" style="left:700px;top:280px;"></div>
<div id="zone" style="left:300px;top:50px;"></div>
<script>
document.onkeydown = pave;
function pave(e) {
e = e || window.event;
if (e.keyCode == '38') {
jump();
}
else if (e.keyCode == '40') {
avancerBottom();
}
else if (e.keyCode == '37') {
avancerLeft();
}
else if (e.keyCode == '39') {
avancerRight();
}
}
</script>
</div>
</body>
</html>
此外,我正在尝试实现一个跳跃 Action ,如果您有任何想法来制作整个 Action 而不仅仅是“传送”,我将不胜感激。
谢谢大家!干杯。
最佳答案
必须做一些调整!
http://codepen.io/smartsendy34/pen/emqdEm
现在向右移动更流畅了!
//使用 JAVASCRIPT
var moveKey = 0;
var moveTime = 0 ;
var frames = 10;
var second = 50;
var fps = second/frames;
function avancerRight()
{
var batman=document.getElementById("batman");
x=parseInt(batman.style.left);
batman.className="dirDroite";
clearTimeout(moveTime);
moveTime = setTimeout(function(){
clearInterval(moveKey);
},second);
clearInterval(moveKey);
moveKey = setInterval(function(){
x = x+(10 / frames);
batman.style.left = x + "px";
},fps);
return false;
}
//使用 JQUERY
function avancerRight()
{
var batman=document.getElementById("batman");
x=batman.style.left;
batman.className="dirDroite";
$(batman).stop().animate({"left":(x+10)},100);
return false;
}
关于javascript - 如何在 Javascript 中平滑地移动 Angular 色(没有 Canvas),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29621501/
我用 geom_line 和 geom_ribbon 创建了一个图(图 1),结果还不错,但为了美观,我希望线条和丝带更平滑。我知道我可以使用 geom_smooth 作为线条(图 2),但我不确定是
我正在使用 Javascript 制作 HTML5 Canvas 游戏。 我想让一个物体平滑地转向某个方向。 我将方向存储为变量,并使用弧度。代码的工作原理如下: window.setInterval
我正在尝试平滑数字列表,出于绘图目的,我不想绘制超过 5000 个项目的图表,因为渲染时间太长,而且我们不需要额外的数据。 假设我们有一个简单的列表: let v = [1,2,3]; // max
我正在尝试制作一款倒置飞扬的小鸟游戏,但我面临一个大问题。 我尝试从上到下生成管道障碍物,但动画看起来很像文本编辑器,而且不流畅,所以我该如何平滑它?我尝试使用 requestanimationfra
我有一些数据由不均匀采样的 2D 空间位置组成,其中每个 x, y 坐标都有一个介于 0 和 2pi 之间的相关相位值 theta。我希望能够将 theta 值插入到常规 x, y 网格中。在相同(或
我有一个(3D)直方图,我喜欢对其应用高斯平滑: cv::MatND Hist; 在 1D 和 2D 情况下,我通过以下方式对其进行模糊处理: cv::GaussianBlur(Hist, Hist,
我的应用程序通过调整其 alpha 值在各种媒体和文本层之间淡入淡出。然而,当使用线性交叉淡入淡出时,亮度似乎在中途“下降”,然后又淡出。经过一番搜索,我找到了 this answer这解释了这个问题
我必须在屏幕上拖动一些 View 。我正在通过触摸监听器的 ACTION_MOVE 上的运动事件更改其布局参数的左侧和顶部来修改它们的位置。有没有办法让“拖动”元素更顺畅?因为这种“拖拽”一点也不顺畅
我只想问有没有你推荐的资源描述Image smoothing简单地。 谢谢。 最佳答案 就像一些评论者提到的那样,图像平滑可能意味着很多事情。但主要是,当有人使用这个术语时,他们的意思是模糊或低通滤波
我有一个带有简单视差的 React 组件,可以更改顶部和不透明度值。问题是滚动动画有点不稳定。有什么办法可以平滑过渡吗?我在 vanilla JS 中使用 requestAnimationFrame(
我在使用 libGDX 获得平滑字体时遇到问题。我已经在这个网站上搜索,并在谷歌上,我尝试了这些问题的解决方案here和 here ,但我的字体渲染效果总是很差。 示例: 我尝试了多种方法,总是得到与
我正在尝试为 Himmelblau's function 绘制一个简单的等高线图(在 gnuplot 中)使用以下代码: f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2
我想知道如何平滑 JScrollPane 的自动过渡。我正在使用 JScrollBar scroll = scollpane.getVerticalScrollBar(); scroll.setVal
我有一个高分辨率的healpix贴图(nside = 4096),我想在给定半径(假设为10 arcmin)的圆盘中对其进行平滑处理。 对healpy非常陌生,在阅读了文档后,我发现一种不太好的方法是
我使用下面的代码在 anchor 链接上平滑滚动 jQuery(function() { jQuery('a[href*=#]:not([href=#])').click(function() {
与这个问题非常相似:Rx IObservable buffering to smooth out bursts of events ,我有兴趣消除可能突然发生的可观察量。 希望下图说明我的目标: Ra
我正在开发代码战链接(一个 div)。我希望 div 内的 svg 在悬停时连续旋转。产生的悬停效果远非平滑,当鼠标在其上滚动时 svg 会跳跃。 mouseout 事件被注释掉了,因为它值得。优化这
有没有办法平滑转换(平移和旋转)的 BufferedImage 的锯齿状边缘? 测试图像的放大 View : (请注意,这不是将要使用的实际 BufferedImage,仅用于此处演示)。 已使用双线
为什么这没有产生平滑的圆?有什么想法吗? public void draw(ShapeRenderer sRenderer) { sRenderer.begin(ShapeType.Fille
我正在做一个项目,我的 ImageView 包含文本和曲线。当在计算机上查看图形时,它们看起来很好。如果带有 ImageView 的应用程序加载到 iPad 2 上,文本(字体:helvetica n
我是一名优秀的程序员,十分优秀!