Created
October 11, 2024 22:57
-
-
Save naosim/f8a1cb20d07ce60a7cb111b50ba877ad to your computer and use it in GitHub Desktop.
【microStudio】小要素を管理するオブジェクト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GameObjects { | |
children = new Set(); | |
constructor() { | |
this.children = new Set(); | |
} | |
add(child) { | |
this.children.add(child); | |
} | |
remove(child) { | |
this.children.delete(child); | |
if(child.destroy) { | |
child.destroy(); | |
} | |
} | |
init() { | |
[...this.children.values()].filter(v => v.init).forEach(v => v.init()); | |
} | |
update() { | |
[...this.children.values()].filter(v => v.update).forEach(v => { | |
v.update(); | |
if(v.isDead) {// 死んでたら削除 | |
this.remove(v); | |
} | |
}); | |
} | |
draw() { | |
[...this.children.values()].filter(v => v.draw).reverse().forEach(v => v.draw()); | |
} | |
destroy() { | |
this.children.forEach(v => this.remove(v)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment