我有以下 HTML 代码:
<img src="game_files/ball.png" id="ball" />
这是一个包含球图像的 div(球的顶视图)
这个球我可以用我的箭头键和一些 javacript 向上、向左、向右、向下等移动。我使用以下代码执行此操作:
var ball = function () {
var inited = false,
el,
xcheck = 50,
x = 50,
ycheck = 50,
y = 50,
xspeed = 0,
yspeed = 0,
power = 0.4,
friction = 0.99,
xwind = 0,
ywind = 0,
dead = true,
timer = function(keys) {
if (dead === true) {
return;
}
if (keys[38] === true) {
yspeed += power;
}
if (keys[40] === true) {
yspeed -= power;
}
if (keys[37] === true) {
xspeed += power;
}
if (keys[39] === true) {
xspeed -= power;
}
xspeed = xspeed * friction - xwind;
yspeed = yspeed * friction - ywind;
if (Math.abs(xspeed) < 0.004) {
xspeed = 0;
}
if (Math.abs(xspeed) < 0.004) {
xspeed = 0;
}
x -= xspeed;
y -= yspeed;
plane.move(x,y);
};
return {
init: function() {
if (inited != true) {
inited = true;
el = document.getElementById('ball');
roller.register(timer, 'time');
}
}
};
}();
这一切都有效,但球没有滚动动画!图像只是向左或向右滑动如何添加?我找到了这个教程:http ://www.emanueleferonato.com/2007/06/10/creation-of-realistic-spheres-in-flash-with-textures-and-masking/我认为可以帮助我。
不幸的是,这是一个闪光球(我希望这也适用于 JS)。本教程正是我想要的:一个带有滚动动画的球(请参阅教程末尾附近的教程页面 豹皮球,就在下面:第 26-37 行:如果纹理相对于球的位置。 ..)。
我怎样才能把它应用到我的 JS 球上?有什么想法吗?
亲切的问候和新年快乐
ps 我也使用/加载 jquery
- 编辑 - - - -
创建了一个小提琴:http: //jsfiddle.net/mauricederegt/dhUw5/
1-打开小提琴
2-点击 1
3- 使用箭头键移动球,留在绿地上!
4-看,没有滚动效果