Hi People, hope everyone is doing great.
My team and i are working on a Visual Novel project and we are using Corona SDK to code our entire game. I wanted to seek help and advise from experienced Corona developers on how i could potentially structure my code a bit better that it is well optimized and eat’s up less resources.
Kindly observe the following code:
local tapCount = 0
function TransitionFunc()
tapCount = tapCount + 1
if(tapCount == 1) then
--Sarah Dialog Disappear
transition.to( DialogText,{ alpha = 0, time = 800 } )
--Dialog Text for Kamali
DialogText = display.newText( " What day is it again?.. ", 245, 280, “SceneAssets/GeoSansLight”, 14)
DialogText:setFillColor( 0,0,0 )
DialogText.alpha = 0
--Sarah Dialog Disappear
transition.to( DialogText,{ alpha = 1 ,time = 800 } )
ButtonAppearDisappear()
elseif(tapCount == 2) then
--Kamali Transition Disappear
transition.to( K1,{ alpha = 0,time = 800 } )
--Dialog Text Transition Disappear
transition.to( DialogText,{alpha = 0 ,time = 600} )
--Sarah Name Image Disappears
transition.to( Sarah_Name,{alpha = 0 ,time = 800} )
--Dialog Text for Kamali
DialogText = display.newText( “Tuesday?..”, 245, 280, “SceneAssets/GeoSansLight”, 14)
DialogText:setFillColor( 0,0,0 )
DialogText.alpha = 0
--Kamali Transition Appear
transition.to( K2,{ alpha = 1,time = 800 } )
--Kamali Name Image Appears
transition.to( Kamali_Name,{alpha = 1 ,time = 800} )
--Dialog Text Appears
transition.to( DialogText,{ time = 800, alpha = 1})
ButtonAppearDisappear()
–Inside scene:create
button:addEventListener( “tap”, TransitionFunc )
button:addEventListener( “tap”, ClickSound )
next:addEventListener( “tap”, changeScenes )
next:addEventListener( “tap”, ClickSound )
So i would like to explain what i am doing currently is that i have assigned this TransitionFunc function to the button. Whenever the button is pressed it adds + 1 to the tap Count variable and then the if/elseif structure compares the value to tapCount, depending on the value the previous text and sprite is hidden by alpha = 0 and new sprite and dialogue is generated/visible by transition.to alpha = 1.
Q1)Now i am having a feeling that this might be a poor way of doing things. And i needed your help on how to incorporate Constructors and parameters to control repetitive tasks.
Q2) Is there anyway that i could declare a method of transition.to without parameters and then specify the object, time, and delay later to save lines of repetitive code.
Q3) If anyone has a better logic for a way of doing dialog and character transitions please kindly share with me so that i can structure my thing better.
Your help will be very much appreciated guys, help a brother out.
Thank you