API Documentation

for 0.0.1
Show:

CanvasTexture Class

CanvasTexture Class simplifies the creation of texture from an HTML5 canvas. Any valid canvas can be used to create a texure that can then be attached to a material. Some helpers static methods are implemented to quickly creates some commons shapes (rectangles, circle). Stroke and fill colors can be changed on the fly if update methods is called afterward

Constructor

CanvasTexture

(
  • params
)

Parameters:

  • params Object

    an object containing all the possible parameters for this class. Use it like in the following example. Possible parameters are lisited below.

    • [canvas= a canvas will be created internally if undefined] Canvas optional

      the canvas to use

    • [context] Context optional

      the Mobilizing context to use

    • [width= 100] Number optional

      width the width of the canvas

    • [height= 100] Number optional

      height the height of the canvas

    • [strokeWidth= 1] Number optional

      strokeWidth as an integer

    • [strokeColor] Color optional

      strokeColor as a Mobilizing Color

    • [strokeOpacity= 1] Number optional

      strokeOpacity as a float between 0 and 1

    • [fillColor] Color optional

      fillColor as a Mobilizing Color

    • [fillOpacity= 1] Number optional

      fillOpacity as a float between 0 and 1

Example:

//TODO

Methods

CreateCircle

(
  • params
)
static

CreateCircle prepares a canvas and a path to draw a circle

Parameters:

  • params Object

    object of paramaters

    • radius Number
    • strokeWidth Number
    • strokeColor Color
    • fillColor Color

CreateRect

(
  • params
)
static

CreateRect prepares a canvas and a path to draw a rectangle

Parameters:

  • params Object

    object of paramaters

    • width Number
    • height Number
    • strokeWidth Number
    • strokeColor Color
    • fillColor Color

drawImage

(
  • image
  • x
  • y
  • [width=canvas.width]
  • [height=canvas.height]
)

Draw an Image in the canvas object and updates it.

Parameters:

  • image Image
  • x Number

    x coordinate to start drawing (from upper-left corner)

  • y Number

    y coordinate to start drawing (from upper-left corner)

  • [width=canvas.width] Number optional

    the destination width to draw to

  • [height=canvas.height] Number optional

    the destination height to draw to

drawStyledText

(
  • text
)

Draw an Mobilizing StyledText or StyledLetter in the canvas object and updates it.

Parameters:

fillWithColor

(
  • color
)

Fills the canvas with the given color

Parameters:

  • color Color

    Mobilizing Color to use

getCanvas

() Canvas

Get this texture base canvas

Returns:

Canvas:

canvas

getCanvasContext

() CanvasContext

Get this texture base canvas context, to directly daw on it

Returns:

CanvasContext:

canvasContext

getHeight

() Number

Get the canvas's height

Returns:

Number:

height

getWidth

() Number

Get the canvas's width

Returns:

Number:

width

resizeCanvas

(
  • width
  • height
)

resizeCanvas resizes and refresh the canvasContext interally

Parameters:

  • width Number
  • height Number

setFillColor

(
  • c
)

Parameters:

  • c Color

    new stroke width

setStrokeColor

(
  • c
)

Parameters:

  • c Color

    new stroke width

setStrokeWidth

(
  • w
)

Parameters:

  • w Number

    new stroke width

toRGBAColorString

(
  • color
  • alpha
)
private

toRGBAColorString makes a css rgba color from a Mobilizing Color and an alpha value (0:1)

Parameters:

  • color Color
  • alpha Number

update

()

Updates the current canvas so that it reflects graphically all the changes done (colors, strokeWidth, etc.) Should be called after the changes has been given.