Hi again, your convenience is so valuable to me, and I can’t stop thanking you for that.
Now, I’ve tried to implement composer scene, but every time I go to the scene where the Ball is, and perform it’s Runtime touch listener very advance, the x1 and y1 of the ball turns out to be a nil value, and the “began” phase looks like it has been ignored.
When I wait a few seconds and perform the touch Listener, everything seems to be fine.
This is because of the transition effect I have written in seeBall.lua composer.gotoScene(“Ball”, {effect = “crossFade”, time = 300})
But when I remove the transition effect, just composer.gotoScene(“Ball”), the touch Listener works as expected, no matter how advanced I got to perform it.
Here are my codes:
** The main.lua**
local composer = require( “composer” )
display.setStatusBar( display.HiddenStatusBar)
composer.gotoScene( “seeBall” )
The seeBall.lua
local composer = require(“composer”)
local scene = composer.newScene()
local SeeBall
local gotoGameWorld = function ()
composer.gotoScene(“Ball”, {effect = “crossFade”, time = 300})
end
local tapTheSeeBall = function( event )
if (event.numTaps > 1) then
transition.to( SeeBall, { alpha = 0.9, size = 30, time = 90, onComplete =
function()
transition.to( SeeBall, { alpha = 1, size = 50, time = 10 } )
end } )
elseif (event.numTaps == 1) then
transition.to( SeeBall, {alpha = 0.9, size = 30, time = 90, onComplete =
function()
transition.to( SeeBall, { alpha = 1, size = 50, time = 10, onComplete =
function()
timer.performWithDelay(5, gotoGameWorld)
end
} )
end
} )
end
return true
end
function scene:create ( event )
local sceneGroup = self.view
local phase = event.phase
SeeBall = display.newText(sceneGroup, "SEE BALL", display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)
SeeBall:addEventListener("tap", tapTheSeeBall)
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == “will”) then
elseif (phase == “did”) then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == “will”) then
elseif (phase == “did”) then
end
end
function scene:destroy ( event )
local sceneGroup = self.view
end
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene)
return scene
And the Ball.lua
local composer = require(“composer”)
local scene = composer.newScene()
local Ball
local bounder = 100
local LLCX = display.actualContentWidth
local LLCR = LLCX - bounder
local LLCL = ( LLCX - LLCX ) + bounder
local LLCY = display.screenOriginY
local LLCT = LLCY + bounder
local LLCB = (display.contentHeight - LLCY) - bounder
local Drag
–local watch = display.newText( "event.time: ", display.contentCenterX, Ball.y - 100, system.nativeFontBold, 50 )
Drag = function ( event )
local phase = event.phase
if ( phase == “began” ) then
display.currentStage:setFocus( Ball )
Ball.x1 = event.x
Ball.y1 = event.y
elseif ( phase == “moved” ) then
display.currentStage:setFocus( nil )
Ball.x2 = event.x
Ball.y2 = event.y
Ball.x = Ball.x + ( Ball.x2 - Ball.x1 )
Ball.y = Ball.y + ( Ball.y2 - Ball.y1 )
Ball.x1 = Ball.x2
Ball.y1 = Ball.y2--]]
if ( Ball.x >= LLCR ) then
Ball.x = LLCR
elseif ( Ball.x <= LLCL ) then
Ball.x = LLCL
end
if ( Ball.y <=LLCT ) then
Ball.y = LLCT
elseif ( Ball.y >= LLCB ) then
Ball.y = LLCB
end
elseif ( phase == “ended” or phase == “cancelled” ) then
display.currentStage:setFocus( nil )
end
return true
end
function scene:create( event )
local sceneGroup = self.view
Ball = display.newCircle(sceneGroup, display.contentCenterX, display.contentCenterY, 100 )
Ball:setFillColor(0, 0.7, 0.8, 1)
Runtime:addEventListener(“touch”, Drag)
end
function scene:show ( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:hide ( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:destroy ( event )
local sceneGroup = selfdisplay.view
end
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene)
return scene
I’m getting an error message showing that the x1 and y1 of the Ball is a nil value, meaning, the “began” phase was ignored.
I want the Runtime touch listener perform fine and as expected even though it has been performed very advanced just as after loading it’s composer scene even with transition time. Thank you very much again😊