Hello, I am working on my first app called "touch the monkey" All it is a magic eight ball with a monkey. However i took out the shake event of the eight ball and put in my own touch event for the monkey. So you ask an important question, touch the monkey, and a yes, no, or maybe will pop up on screen. So I cant get it to work
local w = display.contentWidth
local h = display.contentHeight
monkey = display.newImage("monkey.png")
monkey.x = w/2
monkey.y = h/2
local textfield = display.newText("",w/2-5, h/2 + 40, nil, 24)
local options = {"Yes", "No", "Maybe"}
local function touchmonkey (e)
if ("e.phase"== ended) then
textfield.text = options[math.random(1,3)]
end
end
monkey:addEventListener("touch", touchmonkey)
Hey there;
Change
if ("e.phase"== ended) then
to
if (e.phase == "ended") then
Also, please read the forum rules - when you don't post code in < lua > tags it's a real pain to read.
Peach :)
Thanks Peach, what would be a good way to make the text disappear after about 5 seconds?
you could do it one of the following ways :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| transition.to(myText, {alpha = 0, delay = 500})
--or
local function hideText(text, iTime)
local function hideIt()
text.alpha = 0
end
local tmr = timer.performWithDelay(iTime, hideIt)
end
--When you want to hide the text call this
hideText(myText, 500)
--The text will hide after the time you specify |
Thanks Danny, I went with option A, I inserted it into the function and it worked.However, now i cant ask multiple questions without restarting the app. Is their a way I can do that still using option A?
Never mind i figured it out. I had to put in a myText.alpha = 1 before the 'transition.to' line. I thought the computer would know the alpha was 1. What is the logic behind that? tnx