Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Repeated transitions on an image
Started by applecation Nov 02 2010 05:25 AM

2 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

applecation

[GLOBAL: userInfoPane.html]
applecation
  • Observer

  • 2 posts
  • Guests

I'm a noob, let's get that out in the open now. So what I'm trying to do is get an image that has an eventListener attached, hit the event repeatedly. I want an image to go away when touched and then return after a period of time. This part works, what doesn't work is repeating the process. I'll post my code of what I have been playing with.

[lua=auto:0]function boom( event )
local phase = event.phase
local t = event.target
local stage = display.getCurrentStage()

if (phase == "ended") then
print("we are here")
local myIndex = t.myIndex
stage:setFocus( t, event.id )
print("myIndex " .. myIndex )
transition.to( object[myIndex], { time=200, alpha=0} )
media.playEventSound( "beep.caf" )
transition.to( object[myIndex], { time=200, alpha=1.0, delay=2500 } )
end
end

The only code after this function is the screen setup.
uid: 10638 topic_id: 3291 reply_id: 303291


[TOPIC: post.html]
#2

Tim

[GLOBAL: userInfoPane.html]
Tim
  • Contributor

  • 222 posts
  • Alumni

Can you explain what's not working with your code? I tried it and it seems to do what I would expect. Here's a slightly modified version of your code that I was using:

local rect = display.newRect(0, 0, 100, 100)
rect:setFillColor(255,0,0)
function boom( event )
        local phase = event.phase
        local t = event.target
        local stage = display.getCurrentStage()

        if (phase == "ended") then
                print("we are here")
                stage:setFocus( t, event.id )
                transition.to( t, { time=200, alpha=0} )  
                transition.to( t, { time=200, alpha=1.0, delay=2500 } )
        end
end
rect:addEventListener("touch", boom)
                                              
Tim
uid: 8196 topic_id: 3291 reply_id: 10516


[TOPIC: post.html]
#3

applecation

[GLOBAL: userInfoPane.html]
applecation
  • Observer

  • 2 posts
  • Guests

The problem comes in when I use an array to set up the images. On the first time it fires, everything works fine. However when I attempt to hit an image for the second time nothing happens. Essentially I set up some images, it varies on the number which is why I used an array, then I set a listener on each image. What I would like to do is have some images that will disappear when touched and then "respawn" and be available to repeat.
uid: 10638 topic_id: 3291 reply_id: 10560



[topic_controls]
[/topic_controls]