corona


Collisions reporting multiple times in Corona


I am building a game in Corona SDK that involves two types of collisions with two different types of objects. There are 3 objects total in the game, a rocket ship, an asteroid, and a yellow sphere. When the asteroid hits the rocket ship, you lose one life. When a yellow sphere hits the rocket ship, you gain a point. For some reason both the asteroid and the yellow sphere say that they have multiple collisions with the rocket ship when they are only colliding once. I have re-evaluated my code multiple times and I cannot figure out what the problem is. Please help and if you need sample code I can post some.
Collisions have multiple phases. You have to test the phases. Collisions begin and end. There should be an event.phase that tells you what phase your in. There are also pre-collision events too.
You code must be with in any of these two phases,
local crate1 = display.newImage( "crate.png" )
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
crate1.myName = "first crate"
local crate2 = display.newImage( "crate.png" )
physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } )
crate2.myName = "second crate"
local function onCollision( event )
if ( event.phase == "began" ) then
print( "began: " .. event.object1 .. " & " .. event.object2 )
elseif ( event.phase == "ended" ) then
print( "ended: " .. event.object1 .. " & " .. event.object2 )
end
end
crate1.collision = onLocalCollision
crate1:addEventListener( "collision", crate1 )
crate2.collision = onLocalCollision
crate2:addEventListener( "collision", crate2 )
This will help you to avoid multiple collisions.
https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html

Related Links

How can i properly align Arabic text using the Corona SDK?
Can we change physics body properties in runtime - corona sdk
How to slide pages in Corona SDK
Return Data on showwebpopup
How to pause game and display new layer in corona
Corona SDK pathToFile issue
How to integrate fortumo In-App purchase plugin to Corona Sdk game?
How to make the PNG's transparent region not be listened by the EventListener when a touch event happened?
Corona SDK - group with image rect, wrong reference point
CORONA SDK Physics that dont affect every sprite
corona storyboard dispatch event error
Web view Background trasparency
Changing display Image when interacting to other display
Tap on display objects in Corona SDK
Tableviews “slide down” when tapped in Widget 2.0
Display long text in fixed frame in Corona

Categories

HOME
amazon-web-services
ionic2
magento2
gaming
bokeh
systemd
subdomain
loopbackjs
semantic-web
liferay-7
tfs2015
ontology
navigation
tweepy
lda
amazon-emr
jquery-select2-4
sslhandshakeexception
freertos
amazon-elb
temperature
l20n
asciimath
jqxgrid
salt-cloud
codefluent
connection-refused
multi-upload
fluent-migrator
python-appium
offline-caching
echosign
amazon-iam
phpstorm-2016.1
seafile-server
overwrite
shapeless
cups
xvfb
cartopy
variable-variables
spring-restcontroller
oauth2
hdiv
hypothesis-test
haar-classifier
git-tfs
bit-shift
absolute
wysihtml5
.net-micro-framework
image-registration
supertest
entropy
node-apn
datediff
spring.net
popen
prefetch
pbx
haraka
google-identity-toolkit
jsonix
data-management
clp
callouts
declarative
strpos
adjacency-list
openmrs
univocity
django-validation
phpquery
dsa
relational-model
actionpack
encryption-symmetric
image-rotation
angular-ui-select
treeline
prism.js
rails-api
map
application-blocks
strcmp
rautomation
non-ascii-characters
libxml-js
hints
statechart
delphi-xe4
html-frames
ofstream
chefspec
playorm
first-class
prefuse
uipangesturerecognizer
dropshadow
expression-web
snackjs
rtd
ninject-interception
multiple-users
tabbarcontroller
.net-services
rational-unified-process
html-components
tso
icon-language
objectinstantiation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App