Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2019-11-02T14:34:44+00:00 → 2019-11-23T14:15:49+00:00
<language>Javascript</language> | |
| − | |
| − | ---- |
| − | <p> |
| − | Eine Game-Engine repräsentiert eine Grundlage, auf der man Spiele entwickelt. Für meine Games im Wiki binde ich diese Engine ein. |
| − | So eine Grundlagen nutzen Programmierer oft, um wiederkehrende Funktionen nicht immer neu implementieren zu müssen. Man spricht dabei auch von "Bibliotheken". |
| − | </p> |
| − | <br/> |
| − | |
| − | <code id="Game"> |
| − | function Game(canvas, width, height) { |
| − | |
| − | this.canvas = canvas; |
| − | this.width = width; |
| − | this.height = height; |
| − | |
| − | this.getCanvas() = function { |
| − | return this.canvas; |
| − | }; |
| − | |
| − | this.getWidth() = function { |
| − | return this.width; |
| − | }; |
| − | |
| − | this.getHeight() = function { |
| − | return this.height; |
| − | }; |
| − | } |
| − | </code> |
| − | |
| − | <code id="Renderer"> |
| − | function Renderer(game) { |
| − | |
| − | this.game = game; |
| − | this.canvas = game.getCanvas(); |
| − | this.width = game.getWidth(); |
| − | this.height = game.getHeight(); |
| − | |
| − | |
| − | this.setBackground = function(r, g, b) { |
| − | this.canvas.setColor(r, g, b); |
| − | this.canvas.fillRect(0, 0, this.width, this.height); |
| − | }; |
| − | |
| − | this.setBackground = function(color) { |
| − | this.canvas.setColor(color); |
| − | this.canvas.fillRect(0, 0, this.width, this.height); |
| − | }; |
| − | } |
| − | </code> |