Guys,
finally I found the time to practice a bit with LUA ...
I wrote a simple code
- local function main()
- display.setStatusBar(display.HiddenStatusBar)
-
- _W = display.contentWidth
- _H = display.contentHeight
-
- menuScreenGroup = display.newGroup()
-
- square2 = display.newRect(0,0,100,200)
- square2:setFillColor( 255,255,0) --yellow
- square2.x = _W/2; square2.y = _H/2
- square2.name = "square2"
-
- square1 = display.newRect(0,0,100,200)
- square1:setFillColor( 255,255,255) --white
- square1.x = _W/2 -150; square1.y = _H/2
- square1.name = "square1"
-
- square3 = display.newRect(0,0,100,200)
- square3:setFillColor( 255,0,255) --purple
- square3.x = _W/2 +150; square3.y = _H/2
- square3.name = "square3"
-
- menuScreenGroup:insert(square1)
- menuScreenGroup:insert(square2)
- menuScreenGroup:insert(square3)
-
- square1:addEventListener("tap", loadGame)
-
- end
- function loadGame(event)
- if event.target.name == "square1" then
-
- transition.to(square1, {time=100, y=200})
-
- transition.to(square2, {time=700, x=_W/2-150})
-
- transition.to(square1, {time=1000, x=_W/2})
-
- transition.to(square1, {time=1000, y=_H/2})
-
- square1:removeEventListener("tap", loadGame)
- end
- end
- main()
My idea is to have 3 squares ... and after click the first square ... move exchange the position of square1 and square2.
I have 2 question:
1. I did the transition of square1 in 3 steps (up (line34) then right (line38) and finally down (line40)) .. but instead of the separate movements .. I have only one .. on the right :( why?
2. Due to I want randomly move one of the squares .. I tried creating a table like
T1 = { S1="square1", S2="square2", S3="square3"}
I was thinking to use T1.[S1] in the transition call .. but nothing move even if T1.S1 contains correctly the "square1" value ... but maybe is only a text ..how to use it as "variable" name?
What I'm doing wrong?
Cheers my friends
Dario