ball resets and drops

Hey,

I am wondering how we can have two buttons, one button to reset and another to drop. Once you press the drop button a ball falls down, if you press reset it resets in the same location again. Then you would press drop and it would then drop again, it would be an ongoing process. You press drop, ball drops. You press reset, the ball resets. You then press drop, then the ball drops. I have some code here to give an example of what i mean, but when i try to drop the same ball again it won't drop after the second time.... Any help? I just want an ongoing process of resetting and dropping. Does anyone know or can give an example on how this can be done?

Thanks so much.

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
local ui = require("ui")
require "physics"
physics.start()
 
local ball = display.newCircle( 0, 0, 12.5)
ball:setFillColor(0, 255, 0)
ball.x = display.contentWidth/1.1
ball.y = display.contentHeight/4
 
 
 
function button2Press(event)
 
ball.isVisible = false
 
local ball = display.newCircle( 0, 0, 12.5)
ball:setFillColor(0, 255, 0)
ball.x = display.contentWidth/1.1
ball.y = display.contentHeight/4
 
drop.isVisible = true
reset.isVisible = false
 
 
 
 
end
 
 
reset = ui.newButton{
        default = "reset.png",
        over = "reset.png",
        onPress = button2Press,
        emboss = true
}
 
reset.x = display.contentWidth/1.1
reset.y = display.contentHeight/12
reset.rotation = 0
 
 
reset.isVisible = false
 
button1Press = function( event )
physics.addBody(ball, {bounce=0.3, radius = 12.5, friction=0.5, density = 5})
drop.isVisible = false
reset.isVisible = true
 
 
end
 
 drop = ui.newButton{
        default = "drop.png",
        over = "drop.png",
        onPress = button1Press,
        emboss = true
}
 
 
drop.x = display.contentWidth/1.1
drop.y = display.contentHeight/12
drop.rotation = 0
views:1378 update:2011/9/26 15:43:22
corona forums © 2003-2011