1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| var g_balls = []; // global
// constructor
function Ball(radius, x, y, z, transformNode) {
this.radius = radius;
this.x = x;
this.y = y;
this.z = z;
this.dx = x;
this.dy = y;
this.transformNode = transformNode;
}
// then in another function i create an instance
function createBall(radius) {
...
// create object
var newBall = new Ball(radius, 0.0, 80.0, 0.0, newBallNode);
g_balls[g_ballCount] = newBall;
...
}
function update(index) {
g_debug.innerHTML = 'dx : ' + g_balls[index].dx + ' dy' + g_balls[index].dy;
window.setTimeout(moveBall(index), REFRESH_RATE);
}
function trigger(index) {
g_balls[index].dx =0;
g_balls[index].dy = 4;
g_debug.innerHTML = 'dx : ' + g_balls[index].dx + ' dy' + g_balls[index].dy;
update(index);
} |
Partager