As you probably know in Bubble Ball, in game, there is a start button and when it is pressed everything starts such as like the ball drops and the wood ramps drop because they are all affected by gravity. I would like to know how to make all the physics engines turn on with a button press?!
Please Help-
auksfrailco5
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
Start Physics Engine With Button Press??
--on press
physics.start()
?
or you can also do it like this
--on press
physics.setGravity(0, 9.8)
--If reset or whatever..
physics.setGravity(0, 0)
Ok yes that is what i am looking for but my buttons are not working, I have the ui.lua and i dont really know what to do!!
Help-
auksfrailco5
Post your code.
Here is all my code, if you could, could you pleas like add a button to the code!!
Thanks-
auksfrailco5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | display.setStatusBar( display.HiddenStatusBar ) local physics = require("physics") physics.start() physics.setGravity( 0, 9.81) -- 9.81 m/s*s in the positive x direction physics.setScale(200) -- 200 pixels per meter local background = display.newImage("bg.png") local ground = display.newImage("ground.png") ground.y = 310 physics.addBody( ground, "static", { friction = 1.0, bounce = 0.6, density = 1.0 } ) local ballBody = { density=0.8, friction=0.3, bounce=0.1, radius=18 } local ball = display.newImage("black.png") ball.x = 25 ball.y = 60 ball.linearDamping = 0.3 ball.angularDamping = 0.8 physics.addBody( ball, ballBody ) local ramp = display.newImage("ramp.png") ramp.x = 40 ramp.y = 290 ramp.rotation = 30 physics.addBody( ramp, "static", { friction = 1.0, bounce = 0.0, density = 1.0 } ) ramp.isPlatform = true local ramp1 = display.newImage("ramp.png") ramp1.x = 90 ramp1.y = 290 ramp1.rotation = 170 physics.addBody( ramp1, "static", { friction = 1.0, bounce = 0.0, density = 1.0 } ) ramp1.isPlatform = true local function startDrag( event ) local t = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" -- Stop current motion, if any event.target:setLinearVelocity( 0, 0 ) event.target.angularVelocity = 0 elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false -- Switch body type back to "dynamic", unless we've marked this sprite as a platform if ( not event.target.isPlatform ) then event.target.bodyType = "dynamic" end end end -- Stop further propagation of touch event! return true end ramp:addEventListener( "touch", startDrag ) ramp1:addEventListener( "touch", startDrag ) |
You could really improve that code man.
Why have two references for the same thing ? (ie the ramp)
How about spawning them or having a table of ramps ?
Well I am just experimenting with different bits of code... So if someone could please just help me out with the buttons and just like add a button to the code i would be very happy!!
Thanks-
auksfrailco5
I got it!!
Thanks Guys-
auksfrailco5
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed