Sprite

Pixel~ Sprite

Sprite class.

Constructor

new Sprite(texture)

Source:
Create new Sprite.
Parameters:
Name Type Description
texture Pixel.Texture Pass a texture to be used by the sprite.

Extends

Members

anchor :Pixel.Point

Source:
Overrides:
The anchor position of the sprite.
Type:

deg :number

Source:
Overrides:
Default Value:
  • 0
The degress of rotation on the sprite.
Type:
  • number

flipX :boolean

Source:
Overrides:
Default Value:
  • false
Determines if the sprite is flipped over the x axis.
Type:
  • boolean

flipY :boolean

Source:
Overrides:
Default Value:
  • false
Determines if the sprite is flipped over the y axis.
Type:
  • boolean

height :number

Source:
Overrides:
Height of the Sprite's hitbox.
Type:
  • number

id :string

Source:
Overrides:
Default Value:
  • 0
The id of the sprite, used to find sprites when deleting them.
Type:
  • string

opacity :number

Source:
Overrides:
The opacity of the sprite.
Type:
  • number

point :Pixel.Point

Source:
Overrides:
The position of the sprite.
Type:

scale :number

Source:
Overrides:
Default Value:
  • 1
The scale of the sprite (0 --> 1).
Type:
  • number

texture :Pixel.Texture

Source:
Store the texture for later use.
Type:

width :number

Source:
Overrides:
Width of the Sprite's hitbox.
Type:
  • number

x :number

Source:
Overrides:
X position.
Type:
  • number

y :number

Source:
Overrides:
Y position.
Type:
  • number

Methods

checkCollisions(otherobj) → {object}

Source:
Check if object is colliding with another object. Ported from https://www.w3schools.com/graphics/game_obstacles.asp.
Parameters:
Name Type Description
otherobj Pixel.Sprite The other sprite.
Returns:
Type
object

clone() → {Pixel.Sprite}

Source:
Clones the sprite.
Returns:
Type
Pixel.Sprite

copy(sprite)

Source:
Overrides:
Copy the value of another sprite onto this one.
Parameters:
Name Type Description
sprite Pixel.Sprite Sprite who's values this will copy.

render(ctx)

Source:
Renders sprite.
Parameters:
Name Type Description
ctx CanvasRenderingContext2d The Canvas to print to.

reset(ctx)

Source:
Overrides:
Resets settings set on sprite.
Parameters:
Name Type Description
ctx CanvasRenderingContext2d Context to reset settings on.

rotation_render(ctx)

Source:
Renders the sprite at an angle.
Parameters:
Name Type Description
ctx CanvasRenderingContext2d The Canvas to print to.

setAnchor(x, y)

Source:
Overrides:
Set the position the sprite is anchored to (0-->1).
Parameters:
Name Type Description
x number X position, scale of 0 to 1.
y number Y position, scale of 0 to 1.

setSize(w, h)

Source:
Overrides:
Sets the hitbox size of the sprite.
Parameters:
Name Type Description
w number Width.
h number Height.

settings(ctx)

Source:
Overrides:
Applies settings set on sprite.
Parameters:
Name Type Description
ctx CanvasRenderingContext2d Context to apply settings to.

spin(num)

Source:
Overrides:
Spins x * 360 degrees.
Parameters:
Name Type Description
num number Amount of times sprite rotates 360 degrees.