Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with collisions
Started by akda10 Feb 13 2017 11:32 AM

2 replies to this topic
collision

Best Answer retrofitProductions , 14 February 2017 - 12:56 AM

Could you confirm that your collision handler is being fired, so do you see the values of your print statements?

Also, are you sure that the stars reside in the layer called 'Layer_1'?

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

akda10

[GLOBAL: userInfoPane.html]
akda10
  • Observer

  • 4 posts
  • Corona SDK

Hello!

 

I have a problem with collisions. In LDX i made a level and has placed "stars" which player must to collect.

Main player has been created manually.

There is a part of code of code:


local proj = display.newCircle( 150, 100, 15 )
physics.addBody( proj, { density=1.0, friction=0.3, bounce=0.2 } )
myLevel:addObject('Layer_1', proj)

local function realPlayerCollision(self, event )

	local collisionClass = event.other.class
	print(collisionClass)
	if (string.len(collisionClass) > 0 ) then
	print ('collision ' .. event.phase .. ' with object class',collisionClass,event.other.name)
	end
	
	if ( event.phase == "began" ) then	
		if (collisionClass == 'stars') then
			myLevel:removeLayerObject("Layer_1",event.other.name)
		
		end
	end
end


local function onCollision(self, event )
	timer.performWithDelay(1, function() return realPlayerCollision( self, event) end )
end

proj.collision = onCollision
proj:addEventListener( "collision", proj )

This code I code from example Scroller

But in my game this method does not work. Stars dont dissapear(

 

Please help me!)

 



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

  Best Answer

Could you confirm that your collision handler is being fired, so do you see the values of your print statements?

Also, are you sure that the stars reside in the layer called 'Layer_1'?



[TOPIC: post.html]
#3

akda10

[GLOBAL: userInfoPane.html]
akda10
  • Observer

  • 4 posts
  • Corona SDK

Thank you!

I solved that. There is another listener in touch handler. I deleted the last one and it works)




[topic_controls]
[/topic_controls]