Skip to main content
Version: Phaser v4.0.0

Triangle

The Triangle Shape is a Game Object that can be added to a Scene, Group or Container. You can treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling it for input or physics. It provides a quick and easy way for you to render this shape in your game without using a texture, while still taking advantage of being fully batched in WebGL.

This shape supports both fill and stroke colors.

The Triangle consists of 3 lines, joining up to form a triangular shape. You can control the position of each point of these lines. The triangle is always closed and cannot have an open face. If you require that, consider using a Polygon instead.

Constructor

new Triangle(scene, [x], [y], [x1], [y1], [x2], [y2], [x3], [y3], [fillColor], [fillAlpha])

Parameters

nametypeoptionaldefaultdescription
scenePhaser.SceneNoThe Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
xnumberYes0The horizontal position of this Game Object in the world.
ynumberYes0The vertical position of this Game Object in the world.
x1numberYes0The horizontal position of the first point in the triangle.
y1numberYes128The vertical position of the first point in the triangle.
x2numberYes64The horizontal position of the second point in the triangle.
y2numberYes0The vertical position of the second point in the triangle.
x3numberYes128The horizontal position of the third point in the triangle.
y3numberYes128The vertical position of the third point in the triangle.
fillColornumberYesThe color the triangle will be filled with, i.e. 0xff0000 for red.
fillAlphanumberYesThe alpha the triangle will be filled with. You can also set the alpha of the overall Shape using its alpha property.

Scope: static

Extends

Phaser.GameObjects.Shape

Source: src/gameobjects/shape/triangle/Triangle.js#L12
Since: 3.13.0

Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape:


Public Methods

setTo

<instance> setTo([x1], [y1], [x2], [y2], [x3], [y3])

Description:

Sets the positions of the three vertices of this Triangle shape and updates its internal path data for rendering.

Parameters:

nametypeoptionaldefaultdescription
x1numberYes0The horizontal position of the first point in the triangle.
y1numberYes0The vertical position of the first point in the triangle.
x2numberYes0The horizontal position of the second point in the triangle.
y2numberYes0The vertical position of the second point in the triangle.
x3numberYes0The horizontal position of the third point in the triangle.
y3numberYes0The vertical position of the third point in the triangle.

Returns: Phaser.GameObjects.Triangle - This Game Object instance.

Source: src/gameobjects/shape/triangle/Triangle.js#L81
Since: 3.13.0


Inherited Members

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shape: