Good day everyone! I am currently developing a game and I have encountered a problem. I want my character to appear and disappear behind the background. Right now they do this function but in front of the back ground. Is there any way for me to make them do this function but make it look like they are coming out of the background? Like come out behind a curtain perhaps? Thanks!
Hi julianchiu,
can you post a sample of your function?
If you want to make an object appear/disappear then you can use a transition and change the alpha of the object.
Or if you just want to change the layer of an object you have to insert it into another display-group.
Max / CineTek
display.setStatusBar(display.HiddenStatusBar)
local bg = display.newImage(‘gameBg.png’)
local titleBg
local playBtn
local creditsBtn
local titleView
local creditsView
local score
local m1
local m2
local m3
local m4
local m5
local m6
local m7
local m8
local moles
local lastMole = {}
local hit = audio.loadSound(‘hit.wav’)
local timerSource
local currentMoles = 0
local molesHit = 0
local totalMoles = 10
local Main = {}
local startButtonListeners = {}
local showCredits = {}
local hideCredits = {}
local showGameView = {}
local prepareMoles = {}
local startTimer = {}
local showMole = {}
local popOut = {}
local moleHit = {}
local alert = {}
function Main()
titleBg = display.newImage(‘titleBg.png’)
playBtn = display.newImage(‘playBtn.png’, display.contentCenterX - 25.5, display.contentCenterY + 40)
creditsBtn = display.newImage(‘creditsBtn.png’, display.contentCenterX - 40.5, display.contentCenterY + 85)
titleView = display.newGroup(titleBg, playBtn, creditsBtn)
startButtonListeners(‘add’)
end
function startButtonListeners(action)
if(action == ‘add’) then
playBtn:addEventListener(‘tap’, showGameView)
creditsBtn:addEventListener(‘tap’, showCredits)
else
playBtn:removeEventListener(‘tap’, showGameView)
creditsBtn:removeEventListener(‘tap’, showCredits)
end
end
function showCredits:tap(e)
playBtn.isVisible = false
creditsBtn.isVisible = false
creditsView = display.newImage(‘creditsView.png’)
transition.from(creditsView, {time = 300, x = -creditsView.width, onComplete = function()creditsView:addEventListener(‘tap’, hideCredits) creditsView.x = creditsView.x - 0.5 end})
end
function hideCredits:tap(e)
playBtn.isVisible = true
creditsBtn.isVisible = true
transition.to(creditsView, {time = 300, x = -creditsView.width, onComplete = function()creditsView:removeEventListener(‘tap’, hideCredits) display.remove(creditsView) creditsView = nil end})
end
function showGameView:tap(e)
transition.to(titleView, {time = 300, x = -titleView.height, onComplete = function() startButtonListeners(‘rmv’)display.remove(titleView) titleView = nil end})
score = display.newText(‘0’ … ‘/’ … totalMoles, 58, 6, native.systemFontBold, 16)
score:setTextColor(238, 238, 238)
prepareMoles()
end
function prepareMoles()
local moleX = {200, 300}
local moleY = {211, 300}
for a = 1, 8, 1 do
local mole = display.newImage(“mole1.png”, 91, 91)
mole.x = moleX[a]; mole.y = moleY[a]
mole:addEventListener(“tap”, moleHit)
mole.isVisible = true
mole.id = a
moleGroup:insert(mole)
moles[a] = mole
end
startTimer()
end
function startTimer()
timerSource = timer.performWithDelay(1400, showMole, 0)
end
function showMole(e)
if(currentMoles == totalMoles) then
alert()
else
lastMole.isVisible = false
local randomHole = math.floor(math.random() * 8) + 1
lastMole = moles[randomHole]
lastMole:setReferencePoint(display.BottomCenterReferencePoint)
lastMole.yScale = 0.1
lastMole.isVisible = true
Runtime:addEventListener(‘enterFrame’, popOut)
currentMoles = currentMoles + 1
end
end
function popOut(e)
lastMole.yScale = lastMole.yScale + 0.2
if(lastMole.yScale >= 1) then
Runtime:removeEventListener(‘enterFrame’, popOut)
end
end
function moleHit:tap(e)
audio.play(hit)
molesHit = molesHit + 1
score.text = molesHit … ‘/’ … totalMoles
lastMole.isVisible = false
end
function alert()
timer.cancel(timerSource)
lastMole.isVisible = false
local alert = display.newImage(‘alertBg.png’)
alert:setReferencePoint(display.CenterReferencePoint)
alert.x = display.contentCenterX
alert.y = display.contentCenterY
transition.from(alert, {time = 300, xScale = 0.3, yScale = 0.3})
local score = display.newText(haresHit … ‘/’ … totalHares, 220, 190, native.systemFontBold, 20)
score:setTextColor(204, 152, 102)
end
Main()
There is my whole game code. I fixed that problem BUT another problem arose and maybe you can be a big help as well?
I want to add a different type of moles in the same groups BUT that has a different function like take a point away rather than giving one when tapped. How would i go about adding a different mole type with a different hit function? thanks !
Hi julianchiu,
can you post a sample of your function?
If you want to make an object appear/disappear then you can use a transition and change the alpha of the object.
Or if you just want to change the layer of an object you have to insert it into another display-group.
Max / CineTek
display.setStatusBar(display.HiddenStatusBar)
local bg = display.newImage(‘gameBg.png’)
local titleBg
local playBtn
local creditsBtn
local titleView
local creditsView
local score
local m1
local m2
local m3
local m4
local m5
local m6
local m7
local m8
local moles
local lastMole = {}
local hit = audio.loadSound(‘hit.wav’)
local timerSource
local currentMoles = 0
local molesHit = 0
local totalMoles = 10
local Main = {}
local startButtonListeners = {}
local showCredits = {}
local hideCredits = {}
local showGameView = {}
local prepareMoles = {}
local startTimer = {}
local showMole = {}
local popOut = {}
local moleHit = {}
local alert = {}
function Main()
titleBg = display.newImage(‘titleBg.png’)
playBtn = display.newImage(‘playBtn.png’, display.contentCenterX - 25.5, display.contentCenterY + 40)
creditsBtn = display.newImage(‘creditsBtn.png’, display.contentCenterX - 40.5, display.contentCenterY + 85)
titleView = display.newGroup(titleBg, playBtn, creditsBtn)
startButtonListeners(‘add’)
end
function startButtonListeners(action)
if(action == ‘add’) then
playBtn:addEventListener(‘tap’, showGameView)
creditsBtn:addEventListener(‘tap’, showCredits)
else
playBtn:removeEventListener(‘tap’, showGameView)
creditsBtn:removeEventListener(‘tap’, showCredits)
end
end
function showCredits:tap(e)
playBtn.isVisible = false
creditsBtn.isVisible = false
creditsView = display.newImage(‘creditsView.png’)
transition.from(creditsView, {time = 300, x = -creditsView.width, onComplete = function()creditsView:addEventListener(‘tap’, hideCredits) creditsView.x = creditsView.x - 0.5 end})
end
function hideCredits:tap(e)
playBtn.isVisible = true
creditsBtn.isVisible = true
transition.to(creditsView, {time = 300, x = -creditsView.width, onComplete = function()creditsView:removeEventListener(‘tap’, hideCredits) display.remove(creditsView) creditsView = nil end})
end
function showGameView:tap(e)
transition.to(titleView, {time = 300, x = -titleView.height, onComplete = function() startButtonListeners(‘rmv’)display.remove(titleView) titleView = nil end})
score = display.newText(‘0’ … ‘/’ … totalMoles, 58, 6, native.systemFontBold, 16)
score:setTextColor(238, 238, 238)
prepareMoles()
end
function prepareMoles()
local moleX = {200, 300}
local moleY = {211, 300}
for a = 1, 8, 1 do
local mole = display.newImage(“mole1.png”, 91, 91)
mole.x = moleX[a]; mole.y = moleY[a]
mole:addEventListener(“tap”, moleHit)
mole.isVisible = true
mole.id = a
moleGroup:insert(mole)
moles[a] = mole
end
startTimer()
end
function startTimer()
timerSource = timer.performWithDelay(1400, showMole, 0)
end
function showMole(e)
if(currentMoles == totalMoles) then
alert()
else
lastMole.isVisible = false
local randomHole = math.floor(math.random() * 8) + 1
lastMole = moles[randomHole]
lastMole:setReferencePoint(display.BottomCenterReferencePoint)
lastMole.yScale = 0.1
lastMole.isVisible = true
Runtime:addEventListener(‘enterFrame’, popOut)
currentMoles = currentMoles + 1
end
end
function popOut(e)
lastMole.yScale = lastMole.yScale + 0.2
if(lastMole.yScale >= 1) then
Runtime:removeEventListener(‘enterFrame’, popOut)
end
end
function moleHit:tap(e)
audio.play(hit)
molesHit = molesHit + 1
score.text = molesHit … ‘/’ … totalMoles
lastMole.isVisible = false
end
function alert()
timer.cancel(timerSource)
lastMole.isVisible = false
local alert = display.newImage(‘alertBg.png’)
alert:setReferencePoint(display.CenterReferencePoint)
alert.x = display.contentCenterX
alert.y = display.contentCenterY
transition.from(alert, {time = 300, xScale = 0.3, yScale = 0.3})
local score = display.newText(haresHit … ‘/’ … totalHares, 220, 190, native.systemFontBold, 20)
score:setTextColor(204, 152, 102)
end
Main()
There is my whole game code. I fixed that problem BUT another problem arose and maybe you can be a big help as well?
I want to add a different type of moles in the same groups BUT that has a different function like take a point away rather than giving one when tapped. How would i go about adding a different mole type with a different hit function? thanks !