Constructor
new Image(pathopt)
| Name | Type | Attributes | Description |
|---|---|---|---|
path | String | <optional> | The image filepath. (Can also be a dataURI). If not specified, the image is created with no texture |
let playerImage = new gameify.Image("images/player.png");Members
loaded :Boolean
If the image is loaded
- Boolean
opacity :Number
The opaciy of the image
- Number
- Default Value
- 1
(readonly) path
The image filepath. Modifying this will not do anything.
tileData :Object
If the image was derived from a tileset, details about where it came from. Mostly used for serialization. See example below for schema.
- Object
{ // tileData schema:
tileset: Tileset,
position: { x: Number, y: Number }
size: { x: Number, y: Number }
collisionShape: gameify.shapes.Shape OR undefined,
tags: [ String ]
}Methods
changePath(path)
Change and load a new image path. Reset's the image's crop
| Name | Type | Description |
|---|---|---|
path | string | The new image path |
crop(x, y, width, height)
Crop the image
| Name | Type | Description |
|---|---|---|
x | Number | how much to crop of the left of the image |
y | Number | how much to crop of the right of the image |
width | Number | how wide the resulting image should be |
height | Number | how tall the resulting image should be |
draw(context, x, y, w, h, r)
Draw the image to a context
| Name | Type | Description |
|---|---|---|
context | CanvasRenderingContext2D | The canvas context to draw to |
x | Number | The x coordinate to draw at |
y | Number | The y coordinate to draw at |
w | Number | Width |
h | Number | Height |
r | Number | Rotation, in degrees |
fromJSON(data, ref) → {gameify.Image}
Creates a object from JSON data
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- gameify.
Image
getCrop()
Get the image crop. Returns an object with x, y, width, and height properties.
onLoad(callback)
Set a function to be run when the image is loaded
| Name | Type | Description |
|---|---|---|
callback | function | The function to be called when the image is loaded. |
toJSON(keyopt, ref) → {Object}
Convert the object to JSON
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- Object
uncrop()
Remove crop from the image