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

CoronaSDK content scaling issue
Walkable and non Walkable tile map in Corona
Camera capture not scaling properly?
Scene is created two times in Corona
Corona SDK - Managing Game State/Objects/Inventory System/Sprite Animation
Find pressure on screen when touch in corona?
One background image vs repeating pattern/images, for Corona SDK game?
audio.play on specific channel intermittently does not work? (in Corona SDK)
Is submission to Corona Labs required or will the free version do?
How to take picture using hidden camera?
maze collision in corona
corona drag and drop an object on container or reference
Corona SDK - Clip objects in “letterbox” scaling mode
how to remove a view in corona using its id?
Canvas and Object for Coronos
Corona: Double tap / single tap

Categories

HOME
android-studio
bokeh
filesize
initialization
apk
mongoid
bing-search
tcp
sympy
polymer-2.x
mailing-list
lapack
jodatime
orange-api
vmware-workstation
clr
jest
akka-persistence
web-analytics
fido-u2f
kaggle
intel
tortoisemerge
hevc
gravity-forms-plugin
npoi
guice
series
universal
custom-keyboard
django-crispy-forms
variable-variables
strapi
telephonymanager
spring-restcontroller
game-center
1wire
google-prediction
transparency
audio-converter
dredd
webalizer
aws-kinesis-firehose
icecast
cordova-ios
solr-query-syntax
clrs
alertify
google-shopping-api
d3v4
xcode6.4
decoder
seccomp
bbc-micro
apache-pig-grunt
django-redis
psd
management-studio-express
ajax4jsf
godeps
place
directx-9
bjam
mobilefirst-server
cache-manifest
darwin
subfolder
adwords-apiv201402
relationships
ecos
webmethod
wso2bam
jomsocial
jmenubar
void-pointers
delphi-xe4
django-filebrowser
contextswitchdeadlock
daap
telerik-ajax
firebird1.5
jquery-1.4
ios-4.2
multiple-users
cleartype
oracle-pro-c
rawcontacts
external-sorting
inversion
datagridcolumn
remote-working

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