corona


Changing display Image when interacting to other display


I'm new in corona and I'm trying to make a very simple game for android. I have a two display which is "ball" and "stone" both of them have added a physics, now what I'm trying to do is to detect or check if the ball touches the stone then I will change the image of the ball.
Any thought will be highly appreciated.
Steps are given below -
local physics = require( "physics" )
physics.start()
local firstObject = display.newImage( "bkg_ firstObject.png" )
firstObject.x = display.contentWidth / 2
firstObject.y = 100
local secondObject = display.newImage( "bkg_secondObject.png" )
secondObject.x = display.contentWidth / 2
secondObject.y = 400
secondObject.myName = "secondObject"
physics.addBody( secondObject, "static", { friction=0.6, bounce=0.4 } )
local box1 = display.newImage( "crate.png" )
box1.x = 180; crate1.y = -50
box1.myName = "first box"
local box2 = display.newImage( "crate.png" )
box2.x = 180; crate2.y = -150
box2.myName = "second crate"
physics.addBody( box1, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( box2, { density=3.0, friction=0.5, bounce=0.3 } )
---- METHOD 1: Use table listeners (Local Method)
local function methodOfCollision( self, event )
if ( event.phase == "began" ) then
elseif ( event.phase == "ended" ) then
end
end
crate1.collision = methodOfCollision
crate1:addEventListener( "collision", crate1 )
crate2.collision = methodOfCollision
crate2:addEventListener( "collision", crate2 )
---- METHOD 2: Use a runtime listener (Global Method)
local function onGlobalCollision( event )
if ( event.phase == "began" ) then
elseif ( event.phase == "ended" ) then
end
end
Runtime:addEventListener( "collision", onGlobalCollision )
This answer may help you.

Related Links

After Inapp purshase touch action disabled in corona sdk?
How to parse JSON Data in Corona SDK [duplicate]
How to make an object change its look on collision with another object in corona sdk
Drop Down animation for Image on Tap
Sound is not working properly in Corona SDK
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

Categories

HOME
opengl
spring-data
extjs
angular-ui-grid
bokeh
writefile
ant
consul
autocomplete
twitter-fabric
header
gentelella
navigation
facebook-android-sdk
repair
firebase-dynamic-links
kurento
mailing-list
swarm
azure-graph-api
scrape
phpstorm-2017.1
game-maker
bootstrap-switch
deepfreeze
neo4j.rb
multi-upload
firemonkey-style
dragula
miniprofiler
bobo-browse.net
sparkle
region
jsonresult
xcrun
advanced-filter
ms-media-foundation
markov-chains
bean-validation
pdfminer
wdk
pdfnet
runtimeexception
stackpanel
ms-solver-foundation
xll
llvm-ir
spring-restcontroller
swfupload
get-event-store
classnotfoundexception
apache-toree
common-table-expression
roracle
entropy
spring.net
watir-webdriver
exc-bad-access
lvalue
adobe-reader
perl-data-structures
django-testing
mathml
dojo-build
node.js-connect
vaadin4spring
psd
onepage-checkout
management-studio-express
outlook.com
godeps
variable-length-array
apple
gflags
text-align
android-audiomanager
operands
image-rotation
adwords-apiv201402
producer
lmax
visual-c++-2012
libgcc
otl
senchatouch-2.4
rails-api
zend-search-lucene
flipboard
infinite
san
bcdedit
chefspec
lynx
msinfo32
dropshadow
uploading
n-queens
data-dump
nsrangeexception
tablet-pc
asp.net-mvc-views
jmenu
ognl
channelfactory
mongrel
uninstaller
iphone-sdk-4.3
ntruencrypt

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