Sorry, I missed out a rather vital statement there:
Code:
var e = document.createElement("img");
e.src = "images/smallball.gif";
e.style.position = "absolute";
e.style.visibility = "hidden";
e.id = "ball" + arraybuild;
document.body.appendChild(e);
Read the Gecko DOM reference for more information.
Also any ideas for added physics? I have no idea what else i could do.
Here's an example of using basic gravity physics (taken from http://www.twey.co.uk/includes/game/Game.js):
Code:
var s, u, v, a, t;
t = (this.timeFalling = this.timeFalling + 0.01);
u = 0;
a = this.game.gravity;
v = u + a * t;
s = v * t + 0.5 * a * (t * t);
this.move(0, Math.round(v));
t = time, u = initial velocity, a = acceleration (standard Earth gravity is roughly 9.81), v = current velocity (velocity at time t), s = displacement (the distance moved). The other variables are fairly self-explanatory. This code snippet applies to a body falling from a standstill; by giving it a negative initial velocity, it can be adapted to work with an object propelled upwards against gravity, such as one of your balls when bouncing upwards. Applied correctly, it will give a more realistic feel than the constant-speed sine-based algorithm you're using at the moment.
Code:
document.getElementById("ball" + ballbuild.toString()).style.visibility = "visible"
document.getElementById("ball" + ballbuild.toString()).style.left=xdirection[ballbuild]
document.getElementById("ball" + ballbuild.toString()).style.top=sindraw + imagescrollpos
This is inefficient: all those lookups are unnecessary. Perform the lookup once then store the result:
Code:
var ball = document.getElementById("ball" + ballbuild);
ball.style.visibility = "visible";
ball.style.left = xdirection[ballbuild];
ball.style.top = sindraw + imagescrollpos;
Bookmarks