Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

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

1 reply to this topic
collisions removal tables table ids spawned objects
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]

dwane dibbley

[GLOBAL: userInfoPane.html]
dwane dibbley
  • Observer

  • 6 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 = nil
	event.object2 = nil

Runtime:addEventListener( "collision", onGlobalCollision )

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 389 posts
  • Corona SDK