Phaser: GameObjects

This post is part of a Phaser series. Click here to see the first post of the series.

Inside the create function we can add GameObjects to the game.

For example we can draw shapes, like a circle:
function create() {
const circle = this.a…


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

This post is part of a Phaser series. Click here to see the first post of the series.

Inside the create function we can add GameObjects to the game.

For example we can draw shapes, like a circle:

function create() {
  const circle = this.add.circle(100, 100, 90, 0xffffff)
}

This adds a white circle at position (100, 100), with a diameter of 90. Those numbers are expressed in pixels.

The circle variable contains a reference to the newly added circle.

this in the context of the function refers to the scene object.

Another example is this.add.text(), which adds text to the game:

const text = this.add.text(130, 100, "test")

You can customize how text looks, by passing a set of options:

const text = this.add.text(50, 100, "Test", {
  font: "20px Arial",
  fill: "#FFFFFF",
})

Any GameObject as a set of properties. For example we can access the x and y axis positions, in the 2D space, using text.x and text.y.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2021-04-16T05:00:00+00:00) Phaser: GameObjects. Retrieved from https://www.scien.cx/2021/04/16/phaser-gameobjects/

MLA
" » Phaser: GameObjects." flaviocopes.com | Sciencx - Friday April 16, 2021, https://www.scien.cx/2021/04/16/phaser-gameobjects/
HARVARD
flaviocopes.com | Sciencx Friday April 16, 2021 » Phaser: GameObjects., viewed ,<https://www.scien.cx/2021/04/16/phaser-gameobjects/>
VANCOUVER
flaviocopes.com | Sciencx - » Phaser: GameObjects. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/16/phaser-gameobjects/
CHICAGO
" » Phaser: GameObjects." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/04/16/phaser-gameobjects/
IEEE
" » Phaser: GameObjects." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/04/16/phaser-gameobjects/. [Accessed: ]
rf:citation
» Phaser: GameObjects | flaviocopes.com | Sciencx | https://www.scien.cx/2021/04/16/phaser-gameobjects/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.