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 dst
Object The destination canvas. x
Number in pixel The x coord in the destination canvas (based on the handle coord of the image). y
Number in pixel The y coord in the destination canvas (based on the handle coord of the image). alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). w
Number <optional>
The normalized zoom factor on x (1 by default). h
Number <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 dst
Object The destination canvas. x
Number in pixel The x coord in the destination canvas (based on the handle coord of the image). y
Number in pixel The y coord in the destination canvas (based on the handle coord of the image). partx
Number in pixel The x coord of the part in the source canvas. party
Number in pixel The y coord of the part in the source canvas. partw
Number in pixel The width of the part in the source canvas. parth
Number in pixel The height of the part in the source canvas. alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). zx
Number <optional>
The normalized zoom factor on x (1 by default). zy
Number <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 dst
Object The destination canvas. nb
Number the tile number. x
Number in pixel The x coord in the destination canvas (based on the handle coord of the image). y
Number in pixel The y coord in the destination canvas (based on the handle coord of the image). alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). w
Number <optional>
The normalized zoom factor on x (1 by default). h
Number <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 tilew
Number in pixel The Width of one tile. tileh
Number in pixel The Height of one tile. tilestart
Number <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 x
Number in pixel The x coord of the handle of the image. y
Number 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();