@Markus_Ranner
@XeduR
Sorry, gentleman, it’s my fault. I posted two similar topics at the same time, but later flagged one to delete via moderator. Wrong one, seems to me. And, this morning, it was too embarrassing to get your advices lost.
I took your clear examples into account, thank you for that.
Last night I composed a scene, that can clarify and show what I want to invent here.
local composer = require("composer")
local scene = composer.newScene()
local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX
function scene:create(event)
local sceneGroup = self.view
local background = display.newRect(display.screenOriginX, display.screenOriginY, screenW, screenH)
background.anchorX = 0
background.anchorY = 0
background:setFillColor(0)
local key1 = display.newRect (100, 150, 50, 50)
local key2 = display.newRect (200, 250, 50, 50)
local key3 = display.newRect (300, 150, 50, 50)
local sum = 0
function key1:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
self.xScale = 1; self.yScale = 1
display.getCurrentStage():setFocus( nil )
key1:removeEventListener("touch", key1)
if (sum == 0) then
print ("Key 1 was found")
sum = sum + 1
elseif (sum == 1) then
sum = sum + 1
print ("Two keys!")
elseif (sum == 2) then
print ("All keys!")
end
end
end
key1:addEventListener("touch", key1)
function key2:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
self.xScale = 1; self.yScale = 1
display.getCurrentStage():setFocus( nil )
key2:removeEventListener("touch", key2)
if (sum == 0) then
print ("Key 2 was found")
sum = sum + 1
elseif (sum == 1) then
sum = sum + 1
print ("Two keys!")
elseif (sum == 2) then
print ("All keys!")
end
end
end
key2:addEventListener("touch", key2)
function key3:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
self.xScale = 1; self.yScale = 1
display.getCurrentStage():setFocus( nil )
key3:removeEventListener("touch", key3)
if (sum == 0) then
print ("Key 3 was found")
sum = sum + 1
elseif (sum == 1) then
sum = sum + 1
print ("Two keys!")
elseif (sum == 2) then
sum = sum + 1
print ("All keys!")
end
end
end
key3:addEventListener("touch", key3)
local key4 = display.newRect (100, 250, 50, 50)
local key5 = display.newRect (200, 150, 50, 50)
local key6 = display.newRect (300, 250, 50, 50)
function key4:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
display.getCurrentStage():setFocus( nil )
key4:removeEventListener("touch", key4)
key4:removeSelf()
key4 = nil
end
end
key4:addEventListener("touch", key4)
function key5:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
display.getCurrentStage():setFocus( nil )
key5:removeEventListener("touch", key5)
key5:removeSelf()
key5 = nil
end
end
key5:addEventListener("touch", key5)
function key6:touch (e)
if (e.phase == "began") then
self.xScale = 1.3; self.yScale = 1.3
display.getCurrentStage():setFocus(self, e.id)
elseif (e.phase == "ended") then
display.getCurrentStage():setFocus( nil )
key6:removeEventListener("touch", key6)
key6:removeSelf()
key6 = nil
end
end
key6:addEventListener("touch", key6)
--[[local function func ()
if (sum == 3) then
composer.gotoScene( "level2" )
end
end
Runtime:addEventListener ("enterFrame", func)]]
sceneGroup:insert( background )
sceneGroup:insert (key1)
sceneGroup:insert (key2)
sceneGroup:insert (key3)
sceneGroup:insert (key4)
sceneGroup:insert (key5)
sceneGroup:insert (key6)
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 event.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