A plain image with methods to move, rotate and zoom.
Use this if you need performance and are sure that the image is never needed as logic or physics element, otherwise use gamvas.Actor
new gamvas.Image(file, x, y, cx, cy);
file | a JavaScript Image object (see gamvas.Resource) |
x/y | the position of the image (optional) |
cx/cy | the center of rotation of the image (optional) |
gamvas. | A plain image with methods to move, rotate and zoom. |
Functions | |
setRotation | Set certain rotation of the image in radians |
rotate | Rotate the image |
setPosition | Set the position of a image |
move | Move the image |
setScale | Set a certain scale factor |
scale | Scale the image |
setScaleXY | Set a different scale for x and y axis |
setCenter | Set the center for an Image. |
setFile | Sets the image |
draw | draws the image, using its position, rotation and scale information |
setClipRect | Sets the clipping rectangle of a image |
getClipRect | Gets the clipping rectangle of a image as gamvas.Rect |
this.rotate = function( r )
Rotate the image
r | the amount to rotate the image in radians |
gamvas.Image.setRotation http://en.wikipedia.org/wiki/Radians
this.setCenter = function( x, y )
Set the center for an Image. If you have a round object for example with a size of 64 by 64 pixels and you want to rotate it around the center, you would use myObject.setCenter(32, 32);
x/y | the center, as seen of the upper left corner of the object |
this.setClipRect = function( rx, y, w, h )
Sets the clipping rectangle of a image
A clipping rectangle defines which portion of the image will be drawn. It has to be inside the image and is specified by its top left corner and a width and height.
By default, a clipping rectange of x/y = 0/0 and width/height = image width and height is used
rx | either a gamvas.Rect object or the x coordinate of the upper left corner |
y | the y coordinate of the uppder left corner (if rx is not a gamvas.Rect object) |
w | the width of the clipping rectangle (if rx is not a gamvas.Rect object) |
h | the height of the clipping rectangle (if rx is not a gamvas.Rect object) |
Set certain rotation of the image in radians
this.setRotation = function( r )
Rotate the image
this.rotate = function( r )
Set the position of a image
this.setPosition = function( x, y )
Move the image
this.move = function( x, y )
Set a certain scale factor
this.setScale = function( s )
Scale the image
this.scale = function( s )
Set a different scale for x and y axis
this.setScaleXY = function( x, y )
Set the center for an Image.
this.setCenter = function( x, y )
Sets the image
this.setFile = function( f )
draws the image, using its position, rotation and scale information
this.draw = function()
Sets the clipping rectangle of a image
this.setClipRect = function( rx, y, w, h )
Gets the clipping rectangle of a image as gamvas.Rect
this.getClipRect = function()