lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Guys,
finally I found the time to practice a bit with LUA ...

I wrote a simple code

  1. local function main()
  2.     display.setStatusBar(display.HiddenStatusBar)
  3.    
  4.     _W = display.contentWidth
  5.     _H = display.contentHeight
  6.    
  7.     menuScreenGroup = display.newGroup()
  8.    
  9.     square2 = display.newRect(0,0,100,200)
  10.     square2:setFillColor( 255,255,0)  --yellow
  11.     square2.x = _W/2; square2.y = _H/2
  12.     square2.name = "square2"
  13.    
  14.     square1 = display.newRect(0,0,100,200)
  15.     square1:setFillColor( 255,255,255)  --white
  16.     square1.x = _W/2 -150; square1.y = _H/2
  17.     square1.name = "square1"
  18.    
  19.     square3 = display.newRect(0,0,100,200)
  20.     square3:setFillColor( 255,0,255)  --purple
  21.     square3.x = _W/2 +150; square3.y = _H/2
  22.     square3.name = "square3"
  23.    
  24.     menuScreenGroup:insert(square1)
  25.     menuScreenGroup:insert(square2)
  26.     menuScreenGroup:insert(square3)
  27.    
  28.     square1:addEventListener("tap", loadGame)
  29.    
  30. end
  31. function loadGame(event)
  32.     if event.target.name == "square1" then
  33.    
  34.         transition.to(square1, {time=100,  y=200})
  35.        
  36.         transition.to(square2, {time=700,  x=_W/2-150})
  37.        
  38.         transition.to(square1, {time=1000,  x=_W/2})
  39.        
  40.         transition.to(square1, {time=1000,  y=_H/2})
  41.        
  42.         square1:removeEventListener("tap", loadGame)
  43.     end
  44. end
  45. 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