If you wish to follow along with the exact same image shown here, know that it was taken from the top-left section of the file present at:
The image is shown here:
The following steps will help in creating the pieces and choosing an image:
jigsaw
, set the title to Jigsaw Puzzle
, and save it.tlcorner.png
, p1.png
, trcorner.png
, and so on.p 1 1
, the top-right edge piece would be named p 11 1
and the bottom-right piece would have the name p 11 8
.pieces
.fromcamera
and a label with the name Take a Photo
. Set the button scripts to this:on mouseUp loadimage "camera" end mouseUp Make another button, named "fromlibrary" and labeled "Load a Picture", with this script: on mouseUp loadimage "library" end mouseUp
global originalimage, puzzlewidth, puzzleheight, snapdistance, hcount, vcount on opencard setvalues end opencard on setvalues put 900 into puzzlewidth put 662 into puzzleheight put 50 into snapdistance put 11 into hcount put 8 into vcount end setvalues
loadImage
handler, which the two buttons will call in order to get an image from the user's camera or photo album:on loadImage cameratype if puzzlewidth is empty then setvalues if there is an image "original" then delete image "original" mobilePickPhoto cameratype,puzzlewidth,puzzleheight if the result is empty then lock screen set the name of image the number of images to "original" set the width of image "original" to puzzlewidth set the height of image "original" to puzzleheight put the imageData of image "original" into originalImage delete image "original" --makepuzzle --scatter unlock screen else answer the result end if end loadImage
makepuzzle
and scatter
lines are commented out for now, so that you can test the functions so far.The puzzle pieces are now in place and are named in a way that we can take advantage of them later when we manipulate them. If you go to Standalone Application Settings and select iOS or Android, you can give the app a try.
Setting up some test images
If you use the iPad Simulator, you won't be able to test getting an image from the camera, and at first, you will just have the default images in the photo library. To add your own photo, drag images from Finder to the Simulator window, and the image will be added to the Photos library. You can switch to the simulator Home screen to reselect the Jigsaw app using the cmd + Shift + H key combination. This way, you can add a few images to the library in order to select one as the picture for the puzzle.
When LiveCode gets an image from the mobile device, both from the camera and the library or photo album, it places the picture as an image control that is the topmost object on the card. We don't need the image itself, just its imageData
. In the loadImage
handler, the image is made in the same size as the puzzle pieces group, imageData
is stored in the global variable originalimage
, and the image itself is deleted.
Next, we'll transfer the chosen picture to the puzzle pieces.