Hello everyone, I have problem with my game. I’m trying to make a game where after touching the wall our live decreases by 1 and we appear at the beginning. We move with the mouse, where we press, where the object goes. Unfortunately, I can’t do that after the first touch of the wall, the move is stopped and we immadently appear at the beginning with live -1 , there is a possibility that someone will click on the end of the map, where along the way there will be several walls and will lose several lives.
This is the code for this part:
local function ruch(event) if event.phase == "began" then transition.to(statek, {time = 500, x=event.x, y=event.y}) end end Runtime:addEventListener("touch", ruch) local function restoreShip() statek.isBodyActive = false statek.x = display.contentCenterX statek.y = display.contentCenterY transition.to( statek, { alpha=1, time=1000, onComplete = function() statek.isBodyActive = true died = false end }) end local function onCollision(event) if event.phase == "began" then local obj1 = event.object1 local obj2 = event.object2 if (( obj1.myName == "statek" and obj2.myName == "labirynt") or ( obj1.myName == "labirynt" and obj2.myName == "statek")) then local ship local wall if obj1.myName == "statek" then ship = obj1 wall = obj2 elseif obj2.myName == "statek" then ship = obj2 wall = obj1 end if ship then died = true statek.alpha = 0 timer.performWithDelay( 501, restoreShip ) if died == true then Lives = Lives - 1 LivesText.text = "Lives= " .. Lives end end end end end Runtime:addEventListener("collision", onCollision)
Thank you all for every advice