Hi
How would you go about going adding physics.addBody properties to the “star” in this code so I can detect collisions.
display.setStatusBar( display.HiddenStatusBar );
Variables
_W = display.contentWidth; --Returns Screen Width
_H = display.contentHeight; --Returns Screen Height
local starTable = {} – Set up star table
–Set Up Star Table
function initStar()
local star1 = {}
star1.imgpath = “star1.png”; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star in milliseconds
table.insert(starTable, star1); --Insert Star into starTable
local star2 = {}
star2.imgpath = “star2.png”;
star2.movementSpeed = 12000;
table.insert(starTable, star2);
local star3 = {}
star3.imgpath = “star3.png”;
star3.movementSpeed = 14000;
table.insert(starTable, star3);
end
function getRandomStar()
local temp = starTable[math.random(1, #starTable)]
local randomStar = display.newImage(temp.imgpath)
physics.addBody(randomStar, { isSensor = true } )
randomStar.myName = “star”
randomStar.movementSpeed = temp.movementSpeed;
randomStar.x = math.random(0,_W)
randomStar.y = _H + 50
randomStar.rotation = math.random(0,360)
starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=-45,
onComplete = function(self) self.parent:remove(self); self = nil; end
})
end
local temp = starTable[math.random(1, #starTable)]
Star Image Path
local randomStar = display.newImage(temp.imgpath)
Star Name and Speed
randomStar.myName = “star”
randomStar.movementSpeed = temp.movementSpeed; – in milliseconds
Star Starting Point
randomStar.x = math.random(0,_W)
randomStar.y = _H + 50
randomStar.rotation = math.random(0,360)
Moving the Star
starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=-45,
onComplete = function(self) self.parent:remove(self); self = nil; end
})
function startGame()
starTimer1 = timer.performWithDelay(1700,getRandomStar, 0)
starTimer2 = timer.performWithDelay(2300,getRandomStar, 0)
starTimer3 = timer.performWithDelay(2700,getRandomStar, 0)
end
initStar()
startGame()
the code was found at this url;
http://mobile.tutsplus.com/tutorials/corona/creating-a-scrolling-background-with-corona-sdk/
Any help is much appreciated! [import]uid: 23546 topic_id: 12561 reply_id: 312561[/import]
[import]uid: 11769 topic_id: 12561 reply_id: 45951[/import]