new image
Create an image object and load a remote/local png/gif/jpg in it.
image(img)
image(img)
Parameters:
| Name | Type | Description |
|---|---|---|
img |
string | local or url to an jpg/png/gif image. |
- Source:
- codef_core.js, line 397
Properties:
| Name | Type | Description |
|---|---|---|
img |
Object | the dom image object. |
handlex |
Number in pixel | the x coord of the handle (0 by default). |
handley |
Number in pixel | the y coord of the handle (0 by default). |
tilew |
Number in pixel | the Width of a tile (IF this canvas is a tileset). |
tileh |
Number in pixel | the Height of a tile (IF this canvas is a tileset). |
tilestart |
Number | the number of the first tile (usefull for tileset like font). |
Example
// with a local file
var mylogo = new image('logo.png');
// with a remote image
var mylogo = new image('http://www.myremotesite.com/logo.png');
Methods
-
<static> draw
-
Draw the image to a canvas.
image.draw(dst,x,y,alpha, rot,w,h)
Parameters:
Name Type Argument Description dstObject The destination canvas. xNumber in pixel The x coord in the destination canvas (based on the handle coord of the image). yNumber in pixel The y coord in the destination canvas (based on the handle coord of the image). alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). wNumber <optional>
The normalized zoom factor on x (1 by default). hNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 446
Example
myimage.draw(destcanvas,10,10,1,0,1,1); -
<static> drawPart
-
Draw a part of this image to a canvas.
image.drawPart(dst,x,y,partx,party,partw,parth,alpha, rot,zx,zy)
Parameters:
Name Type Argument Description dstObject The destination canvas. xNumber in pixel The x coord in the destination canvas (based on the handle coord of the image). yNumber in pixel The y coord in the destination canvas (based on the handle coord of the image). partxNumber in pixel The x coord of the part in the source canvas. partyNumber in pixel The y coord of the part in the source canvas. partwNumber in pixel The width of the part in the source canvas. parthNumber in pixel The height of the part in the source canvas. alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). zxNumber <optional>
The normalized zoom factor on x (1 by default). zyNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 510
Example
myimage.drawTile(mycanvas,10,10,0,0,50,50,1,0,1,1); -
<static> drawTile
-
Draw a tile from this image to a canvas.
image.drawTile(dst, nb, x, y, alpha, rot, w, h)
Parameters:
Name Type Argument Description dstObject The destination canvas. nbNumber the tile number. xNumber in pixel The x coord in the destination canvas (based on the handle coord of the image). yNumber in pixel The y coord in the destination canvas (based on the handle coord of the image). alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). wNumber <optional>
The normalized zoom factor on x (1 by default). hNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 485
Example
myimage.drawTile(destcanvas,5,10,10,1,0,1,1); -
<static> initTile
-
Init a tileset image.
image.initTile(tilew,tileh, tilestart)
Parameters:
Name Type Argument Description tilewNumber in pixel The Width of one tile. tilehNumber in pixel The Height of one tile. tilestartNumber <optional>
The number of the first tile. (0 by default) - Source:
- codef_core.js, line 427
Example
myimage.initTile(32,32); -
<static> sethandle
-
Set the handle of the image.
image.sethandle(x,y)
Parameters:
Name Type Description xNumber in pixel The x coord of the handle of the image. yNumber in pixel The y coord of the handle of the image. - Source:
- codef_core.js, line 572
Example
myimage.sethandle(50,50); -
<static> setmidhandle
-
Set the handle coord of this image to the center.
- Source:
- codef_core.js, line 559
Example
myimage.setmidhandle();