Game Development Reference
In-Depth Information
Saving Images
You might need to save an image to the device or hard disk saving it for use later. The image can be
saved using the writePNG function:
image = MOAIImage:new()
image:init(64,64)
-- Some drawing code here
image:writePNG("myimage.png")
Resizing Images
resize or resizeCanvas function. The function resize copies the
resizeCanvas copies the image to a canvas with
getRGBA
getColor32 function. These return the data in RGBA or 32-bit integer format.
image:getRGBA(xPos, yPos)
and
image:getColor32(xPos, yPos)
Similarly, the pixels can be set using the setRGBA and setColor32 functions:
image:setRGBA(xPos, yPos, red, green, blue, alpha)
image:setColor32(xPos, yPos, colour)
Animation
Basic frame-by-frame animation works by changing the image in the frame at a set frequency. This is
called the fps or the frames per seconds. However, with other objects such as text, rectangles, and
circles, modifying their attributes over time would provide the effect of animation.
To get or set the position of the prop, you can use the getLoc or the setLoc function. This is the equivalent
of setting an attribute for a prop.
x, y = prop:getLoc()
is the equivalent of
x = prop:getAttr( MOAISprite2D.ATTR_X_LOC )
y = prop:getAttr( MOAISprite2D.ATTR_Y_LOC )
 
Search WWH ::




Custom Search