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 [import]uid: 44060 topic_id: 8036 reply_id: 308036[/import]
–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) [import]uid: 6981 topic_id: 8036 reply_id: 28616[/import]
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
[import]uid: 44060 topic_id: 8036 reply_id: 28618[/import]
Post your code. [import]uid: 11809 topic_id: 8036 reply_id: 28620[/import]
Here is all my code, if you could, could you pleas like add a button to the code!!
Thanks-
auksfrailco5
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 )
[import]uid: 44060 topic_id: 8036 reply_id: 28622[/import]
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 ?
[import]uid: 6981 topic_id: 8036 reply_id: 28626[/import]
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 [import]uid: 44060 topic_id: 8036 reply_id: 28633[/import]
I got it!!
Thanks Guys-
auksfrailco5 [import]uid: 44060 topic_id: 8036 reply_id: 28642[/import]