Transitions

Hey
 
I am wondering if there is any “fade in” transitions available ?
 
Currently it is  (This is the transitions for the title on my menu screen) :
 

transition.to(i, {x = 164, y = 110, time = 500, delay = 100, transition = easing.inOutExpo})

 

I want to change the transitions so that the title fades in slowly.

 

thanks

Yeah, it’s the alpha (opacity) you want.

You can create an object and set the alpha to 0:

local gameTitle = display.newImage(“gametitle.png”)

gameTitle.alpha = 0

And then do this when you want to fade it in:

transition.to( gameTitle, { time=1000, alpha=1 } )

That should give you a nice fade-in effect.

 Jay

@ Jay

 

Thank you so much and yes I got a nice fade-in effect for my title !

 

Another thing I have been trying to figure out is I want to add some effects on the title to make it look like it is moving a bit (Like how bubbles float in its place, without moving). For example, if we tie a balloon to a chair, the balloon keeps on moving a bit left, right, up or down but doesn’t fly away. I want to add the same effect on the title. However I tried using physics.addBody () but the object moves out of the screen.

 

Out of topic : I just bought your “Mastering Corona SDK course” from Udemy and I am going to start with it in few minutes! Thank you for such amazing course :slight_smile:

 

Thanks.

Oooh, I got this one!  Love doing this.

 

local gameTitle = display.newImage("gametitle.png") local gameTitle.x = display.contentWidth \* 0.5 local gameTitle.y = display.contentHeight \* 0.5 local originalX, originalY, originalRotation = gameTitle.x, gameTitle.y, gameTitle.rotation local function floatTitle() local newX = originalX + math.random( -3, 3 ) local newY = originalY + math.random( -3, 3 ) local newRotation = originalRotation + math.random( -3, 3 ) gameTitle.trans = transition.to( gameTitle, { time = 2000, x = newX, y = newY, rotation = newRotation, onComplete = floatTitle } ) end floatTitle()

 

Just be sure to cancel the transition loop before you exit the scene with 

transition.cancel( gameTitle.trans )

@ BeyondtheTech

 

I tried the way you suggested and it works fine except the size of my title. The size becomes too big that it does’t fit the screen. How can I alter the size of the title image ?

 

Here’s my code: 

 

[lua] local i = display.newImage(“title.png”, 320, 220)
i.x = 164
i.y = 120
i.alpha = 0
localGroup:insert(i)
title = i local originalX, originalY, originalRotation = i.x, i.y, i.rotation
local function floatTitle()
    local newX = 164 + math.random( -3, 3 )
    local newY = 120 + math.random( -3, 3 )
    local newRotation = originalRotation + math.random( -3, 3 )
    i.trans = transition.to( i, { time = 500, x = newX, y = newY, alpha = 1, rotation = newRotation, onComplete = floatTitle } )
end floatTitle()[/lua]

Two ways to make the title smaller. First, just resize the image. :slight_smile:

 

Second, do it in code like this:

 

i:scale(.5, .5)

 

That will scale the title down 50% width and 50% height. The values in scale() are a percentage, where 1 is 100%, 2 is 200%, etc.

 

 Jay

Got it ! 

Thanks ! :slight_smile:

Third is also by setting the arguments when loading the image.

local i = display.newImage("title.png", 240, 165)

 

It will override the dimensions of the image and squish it into the width and height you specify.

Thank you so much, I resized my image and it works perfectly now :smiley:

 

I tried to add effects on my buttons when I click them, so I created a function to animate the buttons when they are clicked.

 

Here’s the code to animate the buttons:

 

[lua]doanim = function(obj) – global function to animate buttons
    local obj = obj
    transition.to(obj, { time = 100, xScale = 1.2, yScale = 1.2 })
    transition.to(obj, { delay = 100, time = 300, xScale = 1, yScale = 1 })
end[/lua]

 

Here’s the code to handle when the button is touched:

 

[lua]local touchHelp = function(event)
    local obj = event.target     if event.phase == “ended” then         doanim(obj) – animate button
        audio.play(sounds.popsound) – play pop sound
        storyboard.gotoScene(“help”, “fromBottom”, 300) – go to help.lua
    end
end[/lua]

 

 

I added sound and animation for the clicked buttons and it works fine.

 

Now I want to add more effects to it but I am stuck. My buttons are made up of bubbles and I want to add a popped-bubble effect on to the buttons when they are clicked. I have an image file for a “splashed bubble” effect and I want to add this effect when the buttons are clicked.

 

I have seen someone doing it like this from one of the older forums but I still don’t get it :frowning:

 

[lua]function bubble:Pop()
    if(self.collision)then
        self:removeEventListener(“collision”, self)
    end
    if(self.touch)then
        self:removeEventListener(“touch”,self)
    end     local bubblePop = display.newImageRect(self.gfxGroup, “BubblePop.png”, 250, 250)
    bubblePop.x = self.x
    bubblePop.y = self.y
    bubblePop.xScale = .01
    bubblePop.yScale = .01
    transition.to(bubblePop, {time=150, xScale = 1, yScale = 1, alpha = 0, onComplete = function()
    display.remove(bubblePop)
    bubblePop = nil
    end})     display.remove(self)
    self = nil
end[/lua]

Yeah, it’s the alpha (opacity) you want.

You can create an object and set the alpha to 0:

local gameTitle = display.newImage(“gametitle.png”)

gameTitle.alpha = 0

And then do this when you want to fade it in:

transition.to( gameTitle, { time=1000, alpha=1 } )

That should give you a nice fade-in effect.

 Jay

@ Jay

 

Thank you so much and yes I got a nice fade-in effect for my title !

 

Another thing I have been trying to figure out is I want to add some effects on the title to make it look like it is moving a bit (Like how bubbles float in its place, without moving). For example, if we tie a balloon to a chair, the balloon keeps on moving a bit left, right, up or down but doesn’t fly away. I want to add the same effect on the title. However I tried using physics.addBody () but the object moves out of the screen.

 

Out of topic : I just bought your “Mastering Corona SDK course” from Udemy and I am going to start with it in few minutes! Thank you for such amazing course :slight_smile:

 

Thanks.

Oooh, I got this one!  Love doing this.

 

local gameTitle = display.newImage("gametitle.png") local gameTitle.x = display.contentWidth \* 0.5 local gameTitle.y = display.contentHeight \* 0.5 local originalX, originalY, originalRotation = gameTitle.x, gameTitle.y, gameTitle.rotation local function floatTitle() local newX = originalX + math.random( -3, 3 ) local newY = originalY + math.random( -3, 3 ) local newRotation = originalRotation + math.random( -3, 3 ) gameTitle.trans = transition.to( gameTitle, { time = 2000, x = newX, y = newY, rotation = newRotation, onComplete = floatTitle } ) end floatTitle()

 

Just be sure to cancel the transition loop before you exit the scene with 

transition.cancel( gameTitle.trans )

@ BeyondtheTech

 

I tried the way you suggested and it works fine except the size of my title. The size becomes too big that it does’t fit the screen. How can I alter the size of the title image ?

 

Here’s my code: 

 

[lua] local i = display.newImage(“title.png”, 320, 220)
i.x = 164
i.y = 120
i.alpha = 0
localGroup:insert(i)
title = i local originalX, originalY, originalRotation = i.x, i.y, i.rotation
local function floatTitle()
    local newX = 164 + math.random( -3, 3 )
    local newY = 120 + math.random( -3, 3 )
    local newRotation = originalRotation + math.random( -3, 3 )
    i.trans = transition.to( i, { time = 500, x = newX, y = newY, alpha = 1, rotation = newRotation, onComplete = floatTitle } )
end floatTitle()[/lua]

Two ways to make the title smaller. First, just resize the image. :slight_smile:

 

Second, do it in code like this:

 

i:scale(.5, .5)

 

That will scale the title down 50% width and 50% height. The values in scale() are a percentage, where 1 is 100%, 2 is 200%, etc.

 

 Jay

Got it ! 

Thanks ! :slight_smile:

Third is also by setting the arguments when loading the image.

local i = display.newImage("title.png", 240, 165)

 

It will override the dimensions of the image and squish it into the width and height you specify.

Thank you so much, I resized my image and it works perfectly now :smiley:

 

I tried to add effects on my buttons when I click them, so I created a function to animate the buttons when they are clicked.

 

Here’s the code to animate the buttons:

 

[lua]doanim = function(obj) – global function to animate buttons
    local obj = obj
    transition.to(obj, { time = 100, xScale = 1.2, yScale = 1.2 })
    transition.to(obj, { delay = 100, time = 300, xScale = 1, yScale = 1 })
end[/lua]

 

Here’s the code to handle when the button is touched:

 

[lua]local touchHelp = function(event)
    local obj = event.target     if event.phase == “ended” then         doanim(obj) – animate button
        audio.play(sounds.popsound) – play pop sound
        storyboard.gotoScene(“help”, “fromBottom”, 300) – go to help.lua
    end
end[/lua]

 

 

I added sound and animation for the clicked buttons and it works fine.

 

Now I want to add more effects to it but I am stuck. My buttons are made up of bubbles and I want to add a popped-bubble effect on to the buttons when they are clicked. I have an image file for a “splashed bubble” effect and I want to add this effect when the buttons are clicked.

 

I have seen someone doing it like this from one of the older forums but I still don’t get it :frowning:

 

[lua]function bubble:Pop()
    if(self.collision)then
        self:removeEventListener(“collision”, self)
    end
    if(self.touch)then
        self:removeEventListener(“touch”,self)
    end     local bubblePop = display.newImageRect(self.gfxGroup, “BubblePop.png”, 250, 250)
    bubblePop.x = self.x
    bubblePop.y = self.y
    bubblePop.xScale = .01
    bubblePop.yScale = .01
    transition.to(bubblePop, {time=150, xScale = 1, yScale = 1, alpha = 0, onComplete = function()
    display.remove(bubblePop)
    bubblePop = nil
    end})     display.remove(self)
    self = nil
end[/lua]