You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
921 B
47 lines
921 B
const AC_GAME_OBJECTS = []; |
|
|
|
export class AcGameObject { |
|
constructor() { |
|
AC_GAME_OBJECTS.push(this); |
|
this.timedelta = 0; |
|
this.has_called_start = false; |
|
} |
|
start() { |
|
|
|
} |
|
update() { |
|
|
|
} |
|
on_destroy() { |
|
|
|
} |
|
destroy() { |
|
this.on_destroy(); |
|
|
|
for (let i in AC_GAME_OBJECTS) { |
|
const obj = AC_GAME_OBJECTS[i]; |
|
if (obj === this) { |
|
AC_GAME_OBJECTS.splice(i, 1); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
let last_timestamp; |
|
const step = timestamp => { |
|
for (let obj of AC_GAME_OBJECTS) { |
|
if (!obj.has_called_start) { |
|
obj.start(); |
|
obj.has_called_start = true; |
|
} else { |
|
obj.timedelta = timestamp - last_timestamp; |
|
obj.update(); |
|
} |
|
} |
|
|
|
last_timestamp = timestamp; |
|
requestAnimationFrame(step); |
|
}; |
|
|
|
requestAnimationFrame(step); |