new BaseTexture(source [, scaleMode], resolution)
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
source |
Image | Canvas | the source object of the texture. |
||
scaleMode |
number |
<optional> |
SCALE_MODES.DEFAULT | See SCALE_MODES for possible values |
resolution |
number | the resolution of the texture for devices with different pixel ratios |
- Source:
Members
-
<readonly> hasLoaded :boolean
-
Set to true once the base texture has successfully loaded.
This is never true if the underlying source fails to load or has no texture data.
Type:
- boolean
- Source:
-
<readonly> height :number
-
The height of the base texture set when the image has loaded
Type:
- number
- Source:
-
imageUrl :string
-
Type:
- string
- Source:
-
<readonly> isLoading :boolean
-
Set to true if the source is currently loading.
If an Image source is loading the 'loaded' or 'error' event will be
dispatched when the operation ends. An underyling source that is
immediately-available bypasses loading entirely.Type:
- boolean
- Source:
-
mipmap :boolean
-
Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used
Also the texture must be a power of two size to workType:
- boolean
- Source:
-
premultipliedAlpha :boolean
-
Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)
All blend modes, and shaders written for default value. Change it on your own risk.Type:
- boolean
- Default Value:
-
- true
- Source:
-
<readonly> realHeight :number
-
Used to store the actual height of the source of this texture
Type:
- number
- Source:
-
<readonly> realWidth :number
-
Used to store the actual width of the source of this texture
Type:
- number
- Source:
-
resolution :number
-
The Resolution of the texture.
Type:
- number
- Source:
-
scaleMode :number
-
The scale mode to apply when scaling this texture
Type:
- number
- Default Value:
-
- SCALE_MODES.LINEAR
- Source:
- See:
-
- SCALE_MODES
-
<readonly> source :Image|Canvas
-
The image source that is used to create the texture.
TODO: Make this a setter that calls loadSource();
Type:
- Image | Canvas
- Source:
-
<readonly> width :number
-
The width of the base texture set when the image has loaded
Type:
- number
- Source:
Methods
-
<static> fromCanvas(canvas, scaleMode)
-
Helper function that creates a base texture from the given canvas element.
Parameters:
Name Type Description canvas
Canvas The canvas element source of the texture
scaleMode
number See SCALE_MODES for possible values
- Source:
Returns:
BaseTexture
-
<static> fromImage(imageUrl [, crossorigin] [, scaleMode])
-
Helper function that creates a base texture from the given image url.
If the image is not in the base texture cache it will be created and loaded.Parameters:
Name Type Argument Default Description imageUrl
string The image url of the texture
crossorigin
boolean <optional>
(auto) Should use anonymous CORS? Defaults to true if the URL is not a data-URI.
scaleMode
number <optional>
SCALE_MODES.DEFAULT See SCALE_MODES for possible values
- Source:
Returns:
BaseTexture
-
destroy()
-
Destroys this base texture
- Source:
-
dispose()
-
Frees the texture from WebGL memory without destroying this texture object.
This means you can still use the texture later which will upload it to GPU
memory again.- Source:
-
<protected> loadSource(source)
-
Load a source.
If the source is not-immediately-available, such as an image that needs to be
downloaded, then the 'loaded' or 'error' event will be dispatched in the future
andhasLoaded
will remain false after this call.The logic state after calling
loadSource
directly or indirectly (eg.fromImage
,new BaseTexture
) is:if (texture.hasLoaded)
{
// texture ready for use
} else if (texture.isLoading)
{
// listen to 'loaded' and/or 'error' events on texture
} else {
// not loading, not going to load UNLESS the source is reloaded
// (it may still make sense to listen to the events)
}Parameters:
Name Type Description source
Image | Canvas the source object of the texture.
- Source:
-
update()
-
Updates the texture on all the webgl renderers, this also assumes the src has changed.
- Source:
Fires:
- event:update
-
updateSourceImage(newSrc)
-
Changes the source image of the texture.
The original source must be an Image element.Parameters:
Name Type Description newSrc
string the path of the image
- Source:
Events
-
error
-
Fired when a not-immediately-available source fails to load.
- Source:
-
loaded
-
Fired when a not-immediately-available source finishes loading.
- Source: