Game Development Reference
In-Depth Information
With Codea, images are different from sprites. Images are canvases that are created via code, and
their bits are set using the set method with an x,y-coordinate and a color. The color of a particular
pixel can be obtained by using the get method. Portions of the image can be copied to create new
images using the image.copy function.
Drawing Off-screen
Most of the drawing functions as we have seen in the above paragraphs draw directly on screen.
The drawing functions can be instructed to draw onto a context (a drawing area) as we specify using
the setContext function. When we want the drawing to be resumed back onto the screen context,
we can simply call the setContext function again without passing it any parameters.
myImage = image (400,400)
setContext(myImage)
ellipse(200,200,200)
rect(0,0,100,100)
setContext()
sprite(myImage, WIDTH/2, HEIGHT/2)
Loading Sprites into an Image
While images can be manipulated by getting or setting the pixel colors and created using the
image.copy function, sprites cannot be manipulated in these ways. To be able to manipulate sprite
images, you can copy or load the sprite onto an image using the readImage function, which creates
an image object from the sprite, like so:
myImage = readImage("Planet Cute:Heart")
Saving Images
This saveImage function can help create and save images to the device or Dropbox. The way to save
an image is by passing it the sprite pack—which is either Documents or Dropbox —followed by the file
name. Note that if the file name already exists, the original file will be overwritten, and if the image is
set to nil , then the file specified will be deleted.
saveImage("Documents:theSprite", image)
Note If the device is a retina device, it will save two files when using this function: a retina-sized
image with a @2x suffix and a non-retina image scaled to 50 percent.
 
 
Search WWH ::




Custom Search