Making An Object Fade Out

I have a function that will be called upon a collision that will emulate a little explosion

by having three little spheres transition in 3 different directions than disappear.  I want

to make it look nicer by having the spheres fade out over the 500 milliseconds instead of just

 disappearing in the ball1Destroy() function.  Can someone help me accomplish this.  Thanks!

 

function ball1Split()

    

            function ball1Destroy()

                ball1a:removeSelf()

                ball1a=nil

                ball1b:removeSelf()

                ball1b=nil

                ball1c:removeSelf()

                ball1c=nil

            end

        ball1a= display.newImageRect(  ‘imagesAngles/blue_sphere.png’,10,10 )

        ball1a.x = ball1.x 

        ball1a.y = ball1.y 

        transition.to( ball1a, { time=500,  x=ball1a.x+25, y=ball1a.y+25, onComplete = ball1Destroy} )

        

        ball1b= display.newImageRect(  ‘imagesAngles/blue_sphere.png’,10,10 )

        ball1b.x = ball1.x 

        ball1b.y = ball1.y 

        transition.to( ball1b, { time=500,  x=ball1b.x-25, y=ball1b.y-25} )

            

        ball1c= display.newImageRect(  ‘imagesAngles/blue_sphere.png’,10,10 )

        ball1c.x = ball1.x 

        ball1c.y = ball1.y 

        transition.to( ball1c, { time=500,  x=ball1c.x+25, y=ball1c.y-25} )

        

end

In your transition, just add “alpha=0” as an additional parameter. This will make it fade out, and then it will be cleared from the screen in the clear function.

In your transition, just add “alpha=0” as an additional parameter. This will make it fade out, and then it will be cleared from the screen in the clear function.