Help with transition.to

Hi everyone. Thanks for all your help.

I have one function that makes one image move from point A to point B.

– when I press a button, the image “falls” or moves, and when it reaches point B it removes it self. Good!

– everytime I press the button, point B remove…

–But If I press the button in the middle of the transition… before it gets to point B,

a new image start to fall, and the first image will not remove it self in point B

but the second image yes…

And the first image there is no way to remove it when I go to another scene.

Please I need help

this is the complete code

-- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- -- How to make an app -- By Victor M. Barba -- Copyright 2013 -- All Rights Reserved -- -- Version 1.0 -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[STORYBOARD REQUIRE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local storyboard = require( "storyboard" ) local widget = require "widget" local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[VARIABLES]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local buttonThis local buttonBack local funny local fallLeaf ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[FUNCTIONS]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local function homeWorldHandler()         storyboard.gotoScene( "mainMenu", "fromRight", 200 )         return true end local function buttonBackHandler()         storyboard.gotoScene( "simple", "fromLeft", 200 )         return true end local function greenTrash()     display.remove (fallLeaf) end local function fallOne(event)     fallLeaf = display.newImage("leaf.png")     fallLeaf.x = math.random ( 0, 1000); fallLeaf.y = math.random ( -100, 50)     fallLeaf:rotate(math.random(0, 360))     local smaller = 1 + math.random(-1, 1) / 2     fallLeaf:scale (smaller, smaller)     transition.to(fallLeaf, {time=6000, x = 500, y = 500, onComplete=greenTrash}) end                           ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event )     local group = self.view         local background = display.newImage( "backgroundFunny.png" )     group:insert ( background )          funny = display.newImage( "funnyG1.png" )     group:insert ( funny )     funny.x = 500     funny.y = 400     funny.name = "FunnyG"          funny:addEventListener ("tap", fallOne )               buttonThis = widget.newButton{     defaultFile="buttonHowToDoThis.png",     onRelease = buttonThisHandler     }     group:insert ( buttonThis )     buttonThis.x = 900     buttonThis.y = 650     buttonThis:scale (.6, .6)          buttonBack = widget.newButton{     defaultFile="buttonBack.png",     onRelease = buttonBackHandler     }     group:insert ( buttonBack )     buttonBack.x = 80     buttonBack.y = 710          local newText10 = display.newText("Just tap on my face, to see the falling leaves.", 230, 500, native.systemFont, 26)     group:insert ( newText10 )     newText10:setTextColor(255, 255, 255)      end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event )     local group = self.view               end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene()     display.remove (funnyG)           end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event )     local group = self.view                  if buttonThis then             buttonThis:removeSelf()             buttonThis = nil         end                  if buttonBack then             buttonBack:removeSelf()             buttonBack = nil         end          end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene        

thanks

victor

The reason for that problem is that your variables are GLOBAL to the scene and are being reset when you create the 2nd image with the 2nd button click.

Basically the code

fallLeaf = display.newImage(“leaf.png”)

is resetting the handle / pointer to the object because it is global

Try moving the variables local to the function and changing the function in the example below.

[lua]

    local function fallOne(event)
        local fallLeaf = nil;    
        fallLeaf = display.newImage(“leaf.png”)
        fallLeaf.x = math.random ( 0, 1000);
        fallLeaf.y = math.random ( -100, 50)
        fallLeaf:rotate(math.random(0, 360))
        local smaller = 1 + math.random(-1, 1) / 2
        fallLeaf:scale (smaller, smaller)
     
        local function greenTrash()
            display.remove (fallLeaf)
        end
     
        transition.to(fallLeaf, {time=6000, x = 500, y = 500, onComplete=greenTrash})
     
    end

[/lua]

Let me know if that works

Larry Meadows

Hi doubleslashdesign:

It’s incredible, how some people are just really nice.

You are one of those really nice people.

I don’t even know you, but you made me a huge favor. Thank you very much

and God bless you…

This code, works like magic. Problem was solved instantly!

I don’t know if it is too much to ask, but I have 4 more problems to solve…

would you be so kind, and help me out, if you can, with those problems?

this is one of them…

http://forums.coronalabs.com/topic/37054-help-with-systemgettimer/

Thank you for everything

your friend

Victor

sure, I don’t mind to lend a hand. I’ll take a gander at your link.

Larry

updated that link - let me know how it goes.

The reason for that problem is that your variables are GLOBAL to the scene and are being reset when you create the 2nd image with the 2nd button click.

Basically the code

fallLeaf = display.newImage(“leaf.png”)

is resetting the handle / pointer to the object because it is global

Try moving the variables local to the function and changing the function in the example below.

[lua]

    local function fallOne(event)
        local fallLeaf = nil;    
        fallLeaf = display.newImage(“leaf.png”)
        fallLeaf.x = math.random ( 0, 1000);
        fallLeaf.y = math.random ( -100, 50)
        fallLeaf:rotate(math.random(0, 360))
        local smaller = 1 + math.random(-1, 1) / 2
        fallLeaf:scale (smaller, smaller)
     
        local function greenTrash()
            display.remove (fallLeaf)
        end
     
        transition.to(fallLeaf, {time=6000, x = 500, y = 500, onComplete=greenTrash})
     
    end

[/lua]

Let me know if that works

Larry Meadows

Hi doubleslashdesign:

It’s incredible, how some people are just really nice.

You are one of those really nice people.

I don’t even know you, but you made me a huge favor. Thank you very much

and God bless you…

This code, works like magic. Problem was solved instantly!

I don’t know if it is too much to ask, but I have 4 more problems to solve…

would you be so kind, and help me out, if you can, with those problems?

this is one of them…

http://forums.coronalabs.com/topic/37054-help-with-systemgettimer/

Thank you for everything

your friend

Victor

sure, I don’t mind to lend a hand. I’ll take a gander at your link.

Larry

updated that link - let me know how it goes.