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

CoronaSDK- How to handle touch and tap at the same time
Using pubnub with corona sdk - basic configuration
Corona SDK - Scene being canceled when entering data into a txt
Corona SDK dynamic width objects
Fade text color in Corona SDK
How to maintain the ratio of distance between 2 moving objects in Corona SDK? [closed]
Corona SDK: show emoji/images on native.showAlert()
error when upload Build on app store in corona sdk
How to properly use store.* in conjunction with storyboard
How to set Corona notification big view
Set object or button above the video in corona sdk
selectively upgrade existing sqlite database in corona by comparing database versions
Corona Near Field Comunication (NFR)
How can i make random generated quotes
Using perspective library with Corona SDK
What is the right way to zoom the camera out from a scene view?

Categories

HOME
elasticsearch
xpath
apache-nifi
matrix
exchange-server
workflow
transactions
haproxy
android-emulator
ag-grid
polymer-2.x
jpa-criteria
port
sap-fiori
spring-amqp
angular4
powermock
string-formatting
gmp
data-type-conversion
activeadmin
sharedpreferences
pdf.js
software-packaging
jstree
pubxml
clipboard
iwebbrowser2
boolean-logic
cloveretl
adminer
subclassing
assertions
nsuserdefaults
cordys-opentext
django-crispy-forms
mars-simulator
oauth2
viewcontroller
absolute
autorelease
deployd
roracle
nonlinear-functions
amazon-elastic-beanstalk
cocoa-bindings
fuzzer
piping
apple-configurator
vimperator
flask-security
dsa
gluon-desktop
featuretoggle
hmisc
org-babel
textscan
abstract-factory
mathematical-expressions
password-recovery
configurable-product
global-scope
visual-studio-6
mfmessagecomposeview
miglayout
map
jquery-transit
insertion
sunstudio
ckeditor.net
platform-independent
affinetransform
glx
getopts
asdoc
fuzzy-comparison

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App