Hi ,
Being a Newbie - I am developing a simple game with normal tap functions & character movements. However I am encountering the following problems.
Problem -
-
After some time the questions overlap - in ideal condition, the overlap should not happen - the next question should appear only after the correct character has been tapped. Some times it starts immediately & sometimes - only after few taps have happened.
-
The speed of the characters - increases or decreases on its own. I am unable to regulate it.
-
The right answer sound is not functioning. It functions well in the simulator - but does not work on the device.
-
All the above problems were not occurring, untill the time - I had only 1 scene. As soon as I had more than 1 scene - this started happening. (However, there is no impact scene transition).
Other info - I am using composer() - no problems there.
The code is as follows:
local function game()
– variable to select random no.
i = math.random(#test)
print ( i )
j = math.random(#test)
print (j)
k = math.random(#test)
print (k)
–if j == i then j = math.random(#test)
–if j == k then k = math.random(#test)
–i ~= j ~= k
–l = math.random(#test)
–print (l)
–
–option1
a = test[i]
local text = display.newImage(a)
text.x = math.random(0, display.contentWidth)
text.y = math.random (0, display.contentHeight)
–option 2 -
b = test[j]
local text1 = display.newImage( B) --, 150, 160, native.systemFont, 26)
text1.x = math.random(0, display.contentWidth)
text1.y = math.random (0, display.contentHeight)
– option 3
c = test[k]
local text2 = display.newImage© --, 200, 160, native.systemFont, 26)
text2.x = math.random(0, display.contentWidth)
text2.y = math.random (0, display.contentHeight)
–main Question
local mainText = display.newImage(b,_W/2,_H/2) --, 160, 70, native.systemFont, 72)
sceneGroup:insert(text)
sceneGroup:insert(text1)
sceneGroup:insert(text2)
sceneGroup:insert(mainText)
–Random movement of Text, needs to be called separate - see below how it is being called.
local function moveText()
transition.to(text, {time= 7000, x= math.random(0,_W), y = math.random(0,_H), onComplete = moveText})
transition.to(text1, {time= 7000, x= math.random(0,_W), y = math.random(0,_H) })
transition.to(text2, {time= 7000, x= math.random(0,_W), y = math.random(0,_H)})
–onComplete works even if it is called only once.
end
– onTap function for correct answer
local function onTap(event)
if event.phase == “ended” then
text:removeSelf()
text1:removeSelf()
text2:removeSelf()
mainText:removeSelf()
local t = display.newText(“Well Done”, event.x, event.y, native.systemFont, 26)
playSound(“right”)
transition.to(t, {alpha = 0, time = 2000, onComplete= game})
end
end
– onTap function for other answers
local function onTap1(event)
if event.phase == “ended” then
local t = display.newText(“Try Again”, event.x, event.y, native.systemFont, 26)
playSound(“wrong”)
transition.to(t, {alpha = 0, time = 2000, onComplete = game})
end
end
–function to handle exit button
local function exitBtnPressed(event)
– playSound(“select”)
composer.gotoScene(“scene7”, {effect = “fade”, time = 100})
return true
end
--exit button symbol
local exitBtn = display.newText(“X”,0,0,native.systemFont, 26) --display.newImage(“images/home.png”)
exitBtn.x = xMin+40; exitBtn.y = yMin+40
exitBtn:addEventListener(“tap”, exitBtnPressed)
sceneGroup:insert(exitBtn)
– calling function which is not event based.
moveText()
text1:addEventListener(“touch”, onTap)
text:addEventListener(“touch”, onTap1)
text2:addEventListener(“touch”, onTap1)
end
game()
Please help.
Also - where can I learn about debugging.
Thanks in advance.
