I need a demonstration of two balls that when they collide send us a message. And then they bounce. Here I show you my code in case you want to help me. local background = display.newImageRect( “fondo.jpg”, 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local balloon1 = display.newImageRect( “bola.png”, 50, 50 ) balloon1.surfaceType = “superbounce” balloon1.x = display.contentCenterX balloon1.y = 0 balloon1.alpha = 0.8 local balloon2 = display.newImageRect( “bola.png”, 50, 50) balloon2.surfaceType = “superbounce” balloon2.x = 130 balloon2.y = 120 balloon2.alpha = 0.8 local platform1 = display.newImageRect( “plataforma.jpg”, 350, 25 ) platform1.x = display.contentCenterX platform1.y = display.contentHeight- -50 local platform2 = display.newImageRect( “plataforma.jpg”, 350, 25 ) platform2.x = display.contentCenterX platform2.y = display.contentHeight-530 local platform3 = display.newImageRect( “plataforma.jpg”, 25, 560 ) platform3.x = -5 platform3.y = 240 local platform4 = display.newImageRect( “plataforma.jpg”, 25, 560 ) platform4.x = 330 platform4.y = 240 local physics = require( “physics” ) physics.start() physics.addBody( platform1, “static” ) physics.addBody( platform2, “static” ) physics.addBody( platform3, “static” ) physics.addBody( platform4, “static” ) physics.addBody( balloon1, “dynamic”, { radius=25, bounce=0.3 } ) physics.addBody( balloon2, “dynamic”, { radius=25, bounce=0.3 } ) --local function moveBall( ) --transition.to ( balloon1, { x = 100, y = 310}) – body --end --moveBall() local function onCollision( self, event ) local collideObject = event.contact.isTouching if ( collideObject.surfaceType == “superbounce” ) then local alert = native.showAlert( “Aviso de colision”, “Han colisionado.”, { “Continuar” }, onComplete ) event.contact.bounce = 0.7-- Magnify bounce for this specific collision end end balloon2.collision = onCollision – thanks for your help. Thank you
I need a demonstration of two balls that when they collide send us a message. And then they bounce. Here I show you my code in case you want to help me.
local background = display.newImageRect( "fondo.jpg", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local balloon1 = display.newImageRect( "bola.png", 50, 50 ) balloon1.surfaceType = "superbounce" balloon1.x = display.contentCenterX balloon1.y = 0 balloon1.alpha = 0.8 local balloon2 = display.newImageRect( "bola.png", 50, 50) balloon2.surfaceType = "superbounce" balloon2.x = 130 balloon2.y = 120 balloon2.alpha = 0.8 local platform1 = display.newImageRect( "plataforma.jpg", 350, 25 ) platform1.x = display.contentCenterX platform1.y = display.contentHeight- -50 local platform2 = display.newImageRect( "plataforma.jpg", 350, 25 ) platform2.x = display.contentCenterX platform2.y = display.contentHeight-530 local platform3 = display.newImageRect( "plataforma.jpg", 25, 560 ) platform3.x = -5 platform3.y = 240 local platform4 = display.newImageRect( "plataforma.jpg", 25, 560 ) platform4.x = 330 platform4.y = 240 local physics = require( "physics" ) physics.start() physics.addBody( platform1, "static" ) physics.addBody( platform2, "static" ) physics.addBody( platform3, "static" ) physics.addBody( platform4, "static" ) physics.addBody( balloon1, "dynamic", { radius=25, bounce=0.3 } ) physics.addBody( balloon2, "dynamic", { radius=25, bounce=0.3 } ) --local function moveBall( ) --transition.to ( balloon1, { x = 100, y = 310}) -- body --end --moveBall() local function onCollision( self, event ) local collideObject = event.contact.isTouching if ( collideObject.surfaceType == "superbounce" ) then local alert = native.showAlert( "Aviso de colision", "Han colisionado.", { "Continuar" }, onComplete ) event.contact.bounce = 0.7-- Magnify bounce for this specific collision end end balloon2.collision = onCollision
– thanks for your help. Thank you
Like this we can more easily help you
You have forgotten a line at the end
balloon2:addEventListener( “collision” )
Have a look here https://docs.coronalabs.com/guide/physics/collisionDetection/index.html
Please use code formatting when posting code. It’s the blue <> button in the row of formatting tools with Bold and Italic. Use Copy/Paste and paste your code into the popup window.
Thanks @remi for taking the time to format the code for the community to see.
Rob
I need a demonstration of two balls that when they collide send us a message. And then they bounce. Here I show you my code in case you want to help me.
local background = display.newImageRect( "fondo.jpg", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local balloon1 = display.newImageRect( "bola.png", 50, 50 ) balloon1.surfaceType = "superbounce" balloon1.x = display.contentCenterX balloon1.y = 0 balloon1.alpha = 0.8 local balloon2 = display.newImageRect( "bola.png", 50, 50) balloon2.surfaceType = "superbounce" balloon2.x = 130 balloon2.y = 120 balloon2.alpha = 0.8 local platform1 = display.newImageRect( "plataforma.jpg", 350, 25 ) platform1.x = display.contentCenterX platform1.y = display.contentHeight- -50 local platform2 = display.newImageRect( "plataforma.jpg", 350, 25 ) platform2.x = display.contentCenterX platform2.y = display.contentHeight-530 local platform3 = display.newImageRect( "plataforma.jpg", 25, 560 ) platform3.x = -5 platform3.y = 240 local platform4 = display.newImageRect( "plataforma.jpg", 25, 560 ) platform4.x = 330 platform4.y = 240 local physics = require( "physics" ) physics.start() physics.addBody( platform1, "static" ) physics.addBody( platform2, "static" ) physics.addBody( platform3, "static" ) physics.addBody( platform4, "static" ) physics.addBody( balloon1, "dynamic", { radius=25, bounce=0.3 } ) physics.addBody( balloon2, "dynamic", { radius=25, bounce=0.3 } ) --local function moveBall( ) --transition.to ( balloon1, { x = 100, y = 310}) -- body --end --moveBall() local function onCollision( self, event ) local collideObject = event.contact.isTouching if ( collideObject.surfaceType == "superbounce" ) then local alert = native.showAlert( "Aviso de colision", "Han colisionado.", { "Continuar" }, onComplete ) event.contact.bounce = 0.7-- Magnify bounce for this specific collision end end balloon2.collision = onCollision
– thanks for your help. Thank you
Like this we can more easily help you
You have forgotten a line at the end
balloon2:addEventListener( “collision” )
Have a look here https://docs.coronalabs.com/guide/physics/collisionDetection/index.html
Please use code formatting when posting code. It’s the blue <> button in the row of formatting tools with Bold and Italic. Use Copy/Paste and paste your code into the popup window.
Thanks @remi for taking the time to format the code for the community to see.
Rob