Image is a class which is used to store a single image, for use in 2D games.
Image is derived from Texture, which is a resource managed class. Texture is a simple OO wrapper around the concept of a texture in OpenGL. An Image simply adds the ability to draw to a quad, as well as some rotation per-vertex tinting, and several other bonuses.
Since Image is a child of ResourceManaged, all memory management is taken care of.
Opens an image file, currently supported image types are BMP, GIF, JPEG, PCX, PNG, and TGA. (Images can be any dimensions)
Loading is done via a href=”Coronahttp://corona.sf.net">Corona</a.
Parameters
name
Name of the Image <Resource> to open.
setAlpha
void setAlpha(
ubyte
alpha
)
Sets alpha-component for Image to be used when surface is drawn.
Parameters
alpha
Desired surface-wide alpha component for Image.
flip
void flip(
bool
horizontal,
bool
vertical
)
Flips image, horizontally and/or vertically.
Parameters
horizontal
True if a flip over horizontal axis is desired.
vertical
True if a flip over vertical axis is desired.
stretch
void stretch(
scalar
xFactor,
scalar
yFactor
)
Stretch image by a given factor. For example: 1 = no change, .5 = 50% current size, 10 = 10 times current size.
Parameters
xFactor
Factor for horizontal stretch.
yFactor
Factor for vertical stretch.
resize
void resize(
scalar
width,
scalar
height
)
Resize the image to a specific size.
Parameters
width
New desired with for image.
height
New desired height for image.
Drawing
draw
void draw(
scalar
x,
scalar
y
) const
draws image to the screen at a givem positon.
Parameters
x
X position to draw image at.
y
Y position to draw image at.
draw
void draw(
scalar
x,
scalar
y,
ubyte
vc[]
) const
Draw image to screen at given position.
This version has an extra parameter, a color vertex option. The 3rd parameter is an array of 16 ubytes defining, Starting in the top left corner & going counterclockwise, tint colors for the image. It is possible to make very nice effects with little effort via this option. Things like shading and lighting can be bluffed using this technique.
There are versions of drawRotated and <drawClipped> that have the vc parameter which works in the same manner.
Parameters
x
X position to draw image at.
y
Y position to draw image at.
vc
Array of 16 ubytes defining the colors of the 4 vertices in clockwise order. (Order: R1,G1,B1,A1,...B4,A4)
drawRotated
void drawRotated(
scalar
x,
scalar
y,
scalar
angle
) const
Draw image, rotated about it’s own center by a specified angle.
Parameters
x
X position to draw image at. (before rotation)
y
Y position to draw image at. (before rotation)
angle
Angle (in degrees) to rotate image.
drawRotated
void drawRotated(
scalar
x,
scalar
y,
scalar
angle,
ubyte
vc[]
) const
Draw image, rotated about it’s own center by a specified angle. Includes color vertex option.
Parameters
x
X position to draw image at. (before rotation)
y
Y position to draw image at. (before rotation)
angle
Angle (in degrees) to rotate image.
vc
Array of 16 ubytes defining the colors of the 4 vertices in clockwise order. (Order: R1,G1,B1,A1,...B4,A4)