Exclude collision listener to one object

on line 6 of the code below i have added a Runtime:addEventListener("collision", onCollision) but it is interacting with everything with a body, how to exclude collision listener to one object in this in this case ‘BCloud1.png’

[code]
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

if ( temp.imgpath == “BCloud1.png” ) then
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
Runtime:addEventListener(“collision”, onCollision)
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
end

if ( temp.imgpath == “BCloud2.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

if ( temp.imgpath == “BCloud3.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

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(-30, _W);
randomStar.y = -35;
randomStar.rotation = math.random(0,20) – Rotate the object

starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=500,
onComplete = function(self) self.parent:remove(self); self = nil;
end
}) – Move the star
end–END getRandomStar()
[/code] [import]uid: 225288 topic_id: 36379 reply_id: 336379[/import]

This is the job for collision filters. See: http://developer.coronalabs.com/content/game-edition-collision-detection

[import]uid: 199310 topic_id: 36379 reply_id: 144485[/import]

i have done this :

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  
  
 if ( temp.imgpath == "BCloud1.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )  
 end  
  
 if ( temp.imgpath == "BCloud2.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 if ( temp.imgpath == "BCloud3.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 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(-30, \_W);   
 randomStar.y = -35;  
 randomStar.rotation = math.random(0,20) -- Rotate the object  
  
 starMove = transition.to(randomStar, {  
 time=randomStar.movementSpeed,   
 y=500,  
 onComplete = function(self) self.parent:remove(self); self = nil;   
 end  
 }) -- Move the star  
end--END getRandomStar()  
local function onLocalCollision1( self, event )  
 if ( event.phase == "began" ) then  
print (" Collision1 ")  
 elseif ( event.phase == "ended" ) then  
 end  
end  
  
BCloud1.collision = onLocalCollision1  
BCloud1:addEventListener( "collision", BCloud1.png)  
  

but i get this error : attempt to index global ‘BCoud1’ (a nil value) ?? [import]uid: 225288 topic_id: 36379 reply_id: 144529[/import]

Have you defined BCloud1 as a display object anywhere? I can’t see it in your code above? [import]uid: 33275 topic_id: 36379 reply_id: 144541[/import]

full code:

[code]

function initStar()
local star1 = {}
star1.imgpath = “Cloud1.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 = “Cloud2.png”;
star2.movementSpeed = 12000;
table.insert(starTable, star2);

local star3 = {}
star3.imgpath = “Cloud3.png”;
star3.movementSpeed = 14000;
table.insert(starTable, star3);

local star4 = {}
star4.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
star4.movementSpeed = 16000;
table.insert(starTable, star4);

local star5 = {}
star5.imgpath = “Cloud5.png”;
star5.movementSpeed = 18000;
table.insert(starTable, star5);

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

if ( temp.imgpath == “BCloud1.png” ) then
if BCloud1 then
physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )
end
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
end

if ( temp.imgpath == “BCloud2.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

if ( temp.imgpath == “BCloud3.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

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(-30, _W);
randomStar.y = -35;
randomStar.rotation = math.random(0,20) – Rotate the object

starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=500,
onComplete = function(self) self.parent:remove(self); self = nil;
end
}) – Move the star
end–END getRandomStar()

function startGame()

timerTime1 = 1009
local function countdownTimer()
starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )
timerTime1 = timerTime1-1
–print("time1 " … timerTime1)
end

countdownTimer()
local mainTimer = timer.performWithDelay( 60000, countdownTimer, 10 )
–60000
end–END startGame()

local function star1incr()
starTable[1].movementSpeed = starTable[1].movementSpeed - 20
starTable[2].movementSpeed = starTable[2].movementSpeed - 22,0
starTable[3].movementSpeed = starTable[3].movementSpeed - 25,0
starTable[4].movementSpeed = starTable[4].movementSpeed - 30,0
starTable[5].movementSpeed = starTable[5].movementSpeed - 32,0

–print("star1 " … starTable[1].movementSpeed)
–print("star2 " … starTable[2].movementSpeed)
–print("star3 " … starTable[3].movementSpeed)
–print("star4 " … starTable[4].movementSpeed)
–print("star5 " … starTable[5].movementSpeed)

end

timer.performWithDelay(500, star1incr, 450)
–500
[/code] [import]uid: 225288 topic_id: 36379 reply_id: 144543[/import]

posted the full code [import]uid: 225288 topic_id: 36379 reply_id: 144546[/import]

This is the job for collision filters. See: http://developer.coronalabs.com/content/game-edition-collision-detection

[import]uid: 199310 topic_id: 36379 reply_id: 144485[/import]

i have done this :

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  
  
 if ( temp.imgpath == "BCloud1.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )  
 end  
  
 if ( temp.imgpath == "BCloud2.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 if ( temp.imgpath == "BCloud3.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 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(-30, \_W);   
 randomStar.y = -35;  
 randomStar.rotation = math.random(0,20) -- Rotate the object  
  
 starMove = transition.to(randomStar, {  
 time=randomStar.movementSpeed,   
 y=500,  
 onComplete = function(self) self.parent:remove(self); self = nil;   
 end  
 }) -- Move the star  
end--END getRandomStar()  
local function onLocalCollision1( self, event )  
 if ( event.phase == "began" ) then  
print (" Collision1 ")  
 elseif ( event.phase == "ended" ) then  
 end  
end  
  
BCloud1.collision = onLocalCollision1  
BCloud1:addEventListener( "collision", BCloud1.png)  
  

but i get this error : attempt to index global ‘BCoud1’ (a nil value) ?? [import]uid: 225288 topic_id: 36379 reply_id: 144529[/import]

Have you defined BCloud1 as a display object anywhere? I can’t see it in your code above? [import]uid: 33275 topic_id: 36379 reply_id: 144541[/import]

full code:

[code]

function initStar()
local star1 = {}
star1.imgpath = “Cloud1.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 = “Cloud2.png”;
star2.movementSpeed = 12000;
table.insert(starTable, star2);

local star3 = {}
star3.imgpath = “Cloud3.png”;
star3.movementSpeed = 14000;
table.insert(starTable, star3);

local star4 = {}
star4.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
star4.movementSpeed = 16000;
table.insert(starTable, star4);

local star5 = {}
star5.imgpath = “Cloud5.png”;
star5.movementSpeed = 18000;
table.insert(starTable, star5);

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

if ( temp.imgpath == “BCloud1.png” ) then
if BCloud1 then
physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )
end
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
end

if ( temp.imgpath == “BCloud2.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

if ( temp.imgpath == “BCloud3.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

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(-30, _W);
randomStar.y = -35;
randomStar.rotation = math.random(0,20) – Rotate the object

starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=500,
onComplete = function(self) self.parent:remove(self); self = nil;
end
}) – Move the star
end–END getRandomStar()

function startGame()

timerTime1 = 1009
local function countdownTimer()
starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )
timerTime1 = timerTime1-1
–print("time1 " … timerTime1)
end

countdownTimer()
local mainTimer = timer.performWithDelay( 60000, countdownTimer, 10 )
–60000
end–END startGame()

local function star1incr()
starTable[1].movementSpeed = starTable[1].movementSpeed - 20
starTable[2].movementSpeed = starTable[2].movementSpeed - 22,0
starTable[3].movementSpeed = starTable[3].movementSpeed - 25,0
starTable[4].movementSpeed = starTable[4].movementSpeed - 30,0
starTable[5].movementSpeed = starTable[5].movementSpeed - 32,0

–print("star1 " … starTable[1].movementSpeed)
–print("star2 " … starTable[2].movementSpeed)
–print("star3 " … starTable[3].movementSpeed)
–print("star4 " … starTable[4].movementSpeed)
–print("star5 " … starTable[5].movementSpeed)

end

timer.performWithDelay(500, star1incr, 450)
–500
[/code] [import]uid: 225288 topic_id: 36379 reply_id: 144543[/import]

posted the full code [import]uid: 225288 topic_id: 36379 reply_id: 144546[/import]

This is the job for collision filters. See: http://developer.coronalabs.com/content/game-edition-collision-detection

[import]uid: 199310 topic_id: 36379 reply_id: 144485[/import]

i have done this :

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  
  
 if ( temp.imgpath == "BCloud1.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )  
 end  
  
 if ( temp.imgpath == "BCloud2.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 if ( temp.imgpath == "BCloud3.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 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(-30, \_W);   
 randomStar.y = -35;  
 randomStar.rotation = math.random(0,20) -- Rotate the object  
  
 starMove = transition.to(randomStar, {  
 time=randomStar.movementSpeed,   
 y=500,  
 onComplete = function(self) self.parent:remove(self); self = nil;   
 end  
 }) -- Move the star  
end--END getRandomStar()  
local function onLocalCollision1( self, event )  
 if ( event.phase == "began" ) then  
print (" Collision1 ")  
 elseif ( event.phase == "ended" ) then  
 end  
end  
  
BCloud1.collision = onLocalCollision1  
BCloud1:addEventListener( "collision", BCloud1.png)  
  

but i get this error : attempt to index global ‘BCoud1’ (a nil value) ?? [import]uid: 225288 topic_id: 36379 reply_id: 144529[/import]

Have you defined BCloud1 as a display object anywhere? I can’t see it in your code above? [import]uid: 33275 topic_id: 36379 reply_id: 144541[/import]

full code:

[code]

function initStar()
local star1 = {}
star1.imgpath = “Cloud1.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 = “Cloud2.png”;
star2.movementSpeed = 12000;
table.insert(starTable, star2);

local star3 = {}
star3.imgpath = “Cloud3.png”;
star3.movementSpeed = 14000;
table.insert(starTable, star3);

local star4 = {}
star4.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
star4.movementSpeed = 16000;
table.insert(starTable, star4);

local star5 = {}
star5.imgpath = “Cloud5.png”;
star5.movementSpeed = 18000;
table.insert(starTable, star5);

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

if ( temp.imgpath == “BCloud1.png” ) then
if BCloud1 then
physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )
end
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
end

if ( temp.imgpath == “BCloud2.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

if ( temp.imgpath == “BCloud3.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

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(-30, _W);
randomStar.y = -35;
randomStar.rotation = math.random(0,20) – Rotate the object

starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=500,
onComplete = function(self) self.parent:remove(self); self = nil;
end
}) – Move the star
end–END getRandomStar()

function startGame()

timerTime1 = 1009
local function countdownTimer()
starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )
timerTime1 = timerTime1-1
–print("time1 " … timerTime1)
end

countdownTimer()
local mainTimer = timer.performWithDelay( 60000, countdownTimer, 10 )
–60000
end–END startGame()

local function star1incr()
starTable[1].movementSpeed = starTable[1].movementSpeed - 20
starTable[2].movementSpeed = starTable[2].movementSpeed - 22,0
starTable[3].movementSpeed = starTable[3].movementSpeed - 25,0
starTable[4].movementSpeed = starTable[4].movementSpeed - 30,0
starTable[5].movementSpeed = starTable[5].movementSpeed - 32,0

–print("star1 " … starTable[1].movementSpeed)
–print("star2 " … starTable[2].movementSpeed)
–print("star3 " … starTable[3].movementSpeed)
–print("star4 " … starTable[4].movementSpeed)
–print("star5 " … starTable[5].movementSpeed)

end

timer.performWithDelay(500, star1incr, 450)
–500
[/code] [import]uid: 225288 topic_id: 36379 reply_id: 144543[/import]

posted the full code [import]uid: 225288 topic_id: 36379 reply_id: 144546[/import]

This is the job for collision filters. See: http://developer.coronalabs.com/content/game-edition-collision-detection

[import]uid: 199310 topic_id: 36379 reply_id: 144485[/import]

i have done this :

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  
  
 if ( temp.imgpath == "BCloud1.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )  
 end  
  
 if ( temp.imgpath == "BCloud2.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 if ( temp.imgpath == "BCloud3.png" ) then  
 temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";  
 physics.addBody( randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )   
 end  
  
 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(-30, \_W);   
 randomStar.y = -35;  
 randomStar.rotation = math.random(0,20) -- Rotate the object  
  
 starMove = transition.to(randomStar, {  
 time=randomStar.movementSpeed,   
 y=500,  
 onComplete = function(self) self.parent:remove(self); self = nil;   
 end  
 }) -- Move the star  
end--END getRandomStar()  
local function onLocalCollision1( self, event )  
 if ( event.phase == "began" ) then  
print (" Collision1 ")  
 elseif ( event.phase == "ended" ) then  
 end  
end  
  
BCloud1.collision = onLocalCollision1  
BCloud1:addEventListener( "collision", BCloud1.png)  
  

but i get this error : attempt to index global ‘BCoud1’ (a nil value) ?? [import]uid: 225288 topic_id: 36379 reply_id: 144529[/import]

Have you defined BCloud1 as a display object anywhere? I can’t see it in your code above? [import]uid: 33275 topic_id: 36379 reply_id: 144541[/import]

full code:

[code]

function initStar()
local star1 = {}
star1.imgpath = “Cloud1.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 = “Cloud2.png”;
star2.movementSpeed = 12000;
table.insert(starTable, star2);

local star3 = {}
star3.imgpath = “Cloud3.png”;
star3.movementSpeed = 14000;
table.insert(starTable, star3);

local star4 = {}
star4.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
star4.movementSpeed = 16000;
table.insert(starTable, star4);

local star5 = {}
star5.imgpath = “Cloud5.png”;
star5.movementSpeed = 18000;
table.insert(starTable, star5);

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

if ( temp.imgpath == “BCloud1.png” ) then
if BCloud1 then
physics.addBody( BCloud1, { density=3.0, friction=0.5, bounce=0.3 } )
end
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
end

if ( temp.imgpath == “BCloud2.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

if ( temp.imgpath == “BCloud3.png” ) then
temp.imgpath = “BCloud”…tostring(math.random(1, 3))…".png";
physics.addBody( randomStar, “static”, { density=.1, bounce=.1, friction=.2, radius=45 } )
end

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(-30, _W);
randomStar.y = -35;
randomStar.rotation = math.random(0,20) – Rotate the object

starMove = transition.to(randomStar, {
time=randomStar.movementSpeed,
y=500,
onComplete = function(self) self.parent:remove(self); self = nil;
end
}) – Move the star
end–END getRandomStar()

function startGame()

timerTime1 = 1009
local function countdownTimer()
starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )
timerTime1 = timerTime1-1
–print("time1 " … timerTime1)
end

countdownTimer()
local mainTimer = timer.performWithDelay( 60000, countdownTimer, 10 )
–60000
end–END startGame()

local function star1incr()
starTable[1].movementSpeed = starTable[1].movementSpeed - 20
starTable[2].movementSpeed = starTable[2].movementSpeed - 22,0
starTable[3].movementSpeed = starTable[3].movementSpeed - 25,0
starTable[4].movementSpeed = starTable[4].movementSpeed - 30,0
starTable[5].movementSpeed = starTable[5].movementSpeed - 32,0

–print("star1 " … starTable[1].movementSpeed)
–print("star2 " … starTable[2].movementSpeed)
–print("star3 " … starTable[3].movementSpeed)
–print("star4 " … starTable[4].movementSpeed)
–print("star5 " … starTable[5].movementSpeed)

end

timer.performWithDelay(500, star1incr, 450)
–500
[/code] [import]uid: 225288 topic_id: 36379 reply_id: 144543[/import]