Hi you all, in my endless run game, I’ve added a pause butto, which sets all my object’s speed on “0” if it is pressed once, while if it is pressed twice it sets the object’s speed to their native value.
Here’s it’s code:
local pausebtn = display.newImage("immagini/pause.png")
pausebtn.x =\_W - 15
pausebtn.y =\_H - 15
local function pause()
if paused == false then
physics.pause()
timer.pause(myTimer)
bgSpeed = 0
terraSpeed = 0
marteSpeed = 0
mercurioSpeed = 0
meteoraSpeed = 0
coinSpeed = 0
temp = 0
paused = true
elseif paused == true then
physics.start()
bgSpeed = 1
terraSpeed = 1
marteSpeed = 1
mercurioSpeed = 1
meteoraSpeed = 1
coinSpeed = 1
timer.resume(myTimer)
paused = false
end
end
pausebtn:addEventListener("tap", pause)
now I’ve got the following function, and I want to set the speed of the three stars spawned by it to “0” when I press the pause button (and to set it back to their original speed when I press it again).
Here’s the function:
local function stelle()
local starTable = {} -- Set up star table
function initStar()
local star1 = {}
star1.imgpath = "immagini/star1.png"; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star
table.insert(starTable, star1); --Insert Star into starTable
local star2 = {}
star2.imgpath = "immagini/star2.png";
star2.movementSpeed = 12000;
table.insert(starTable, star2);
local star3 = {}
star3.imgpath = "immagini/star3.png";
star3.movementSpeed = 14000;
table.insert(starTable, star3);
end --END initStar()
function getRandomStar()
local temp = starTable[math.random(1, #starTable)] -- Get a random star from starTable
local randomStar = display.newImage(temp.imgpath) -- Set image path for object
randomStar.myName = "star" -- Set the name of the object to star
randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move
randomStar.x = math.random(0,\_W) -- Set starting point of star at a random X position
randomStar.y = -50 -- Start the star off screen
randomStar.rotation = math.random(0,360) -- Rotate the object
starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=\_H,
onComplete = function(self) self.parent:remove(self); self = nil; end
}) -- Move the star
end--END getRandomStar()
function startGame()
starTimer1 = timer.performWithDelay(1700,getRandomStar, 0)
starTimer2 = timer.performWithDelay(2300,getRandomStar, 0)
starTimer3 = timer.performWithDelay(2700,getRandomStar, 0)
end--END startGame()
initStar()
startGame()
end
tmrStelle = timer.performWithDelay (30000, stelle, 0)
How can I do that?
Thank you all! [import]uid: 122056 topic_id: 36060 reply_id: 336060[/import]