Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

on collision, remove objects from display and table
Started by iansingleton39 Dec 02 2018 09:35 AM

1 reply to this topic
collisions removal tables table ids spawned objects
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

iansingleton39

[GLOBAL: userInfoPane.html]
iansingleton39
  • Observer

  • 2 posts
  • Corona SDK

i'm coding a space invaders style game, i have a large group of 'triangles' at the top, a rocket at the bottom firing lasers upwards... i'm struggling with the concept of collisions and removal of objects. i'm thinking i need all my triangle to have a seperate name/id within a table(spawnedObjects)... hence the 'spawnedObjects' +1.

 

When the laser hits a triangle i get this output :-

table: 0C17AE88
table: 0C3227B8
element1 = 1
element2 = 1

 

It removes the 2 objects from display, but (Q1) do i need to remove the triangle from the table as well?

(Q2) how would i go about this? and (Q3) i'm i going about this the correct way?
 

startDisplay = function ()
		for i = 1, stack [a] do -- 1 to stack[ 1 to 30]
	
		local xx = rowPosY[a] --xx = row position
		local triangle = display.newImageRect( "spriteFolder/set_02.png",16,16 ) --image
		sceneGroup:insert( triangle )
		physics.addBody( triangle, "static")
		triangle.myName ="triangle"
		
		
		spawnedObjects[#spawnedObjects+1] = triangle -- Add triangle to "spawnedObjects" table 
local function onGlobalCollision( event )
   	print( event.object1 )       --the first object in the collision
   	print( event.object2 )       --the second object in the collision
   	print( "element1 = "..event.element1 )      --the element (number) of the first object which was hit in the collision
	print( "element2 = "..event.element2 )      --the element (number) of the second object which was hit in the collision
	
        event.object1:removeSelf()
        event.object2:removeSelf()
	event.object1 = nil
	event.object2 = nil

end
Runtime:addEventListener( "collision", onGlobalCollision )


[TOPIC: post.html]
#2

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
  • Contributor

  • 374 posts
  • Corona SDK

Hi iansingleton39,

 

See 

 

Have a nice day:)

 

ldurniat




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: collisions, removal, tables, table ids, spawned, objects