Created Sunday 24 May 2015
Let's create a simple memory game. Please download the folloing zip file.
http://www.kwiksher.com/tutorials/Memory/memory.zip
You find the psd file and the two extenal code files in the zip
- touchHandler.lua
- memoryGame.lua
Overall steps
- create a group which contains photo layers
- make a variable to let the external code to know which photo is tapped.
- add a button to each photo. set the variable value with photo number and attach touchHandler.lua
- add memoryGame.lua as extenal code
create a group
Create a kwik project with iPad mini using the psd file in the memory.zip.
Project and pages > Create Groups
Insert all photo layers and group name is gp_photos that is refered in the external codes
2.Create a variable
project and pages > Create Variable
photoNum variable is created. It holdes a same number for same photo. For example, photo1 and photo11 layers are same. So we assign 1 to the button of photo1 and photo11
3.Create buttons
Each photo layer is a button with photoNum and with the extenal code of touchHandler.lua
From Code, add Edit Variable and Add External Code.
photo1 and photo11 are set with 1 for photoNum
touchHandler.lua is set
but_11 for photo11. photoNum is 1
but_2 is photo2 and photoNum is 2
but_22 is photo22 and photoNum is 2
Set photoNum and touchHandler.lua to photo3, photo33, photo4 and photo44 as well
4. Finally memoryGame.lua
add memoryGame.lua from project and pages > Add External Code
Insert the lua codes after buttons and actions.
that's all. Publish and test it.
6. lua codes
touchHandler.lua is just one line
layer.hitTest(self)
memoryGame.lua has two parts. showing photos randomly and hitTest function