Touch-Drag to Resize circle?

Hi All,
I'm having trouble integrating this "grow controller" I wish to have a dot that you can pull outwards from the middle to resize, release then resize from it's current radius to a larger or smaller size.
I picture is worth a million words so here goes:

The tricky part is that I don't want it to reset itself to small on the second touch, if that makes sense...

would you recommend a resizable button or to just code it in a touch event handler?

Any pointers to get me started would be greatly appreciated!
Thanks

Alex

i could only come up with this, hope it helps

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
local ball = display.newCircle(0,0,10)
ball.x = 150
ball.y = 150
 
local var = 0
 
local i = 0
local lastscalex = 0
local lastscaley = 0
 
local function drag_resize(event)
if event.phase == "began" then
 
        display.getCurrentStage():setFocus(event.target)
 
i = event.x
elseif event.phase == "moved" then
        if event.x > i then
        var = i + event.x
        
        if var*0.01 > ball.xScale then
        ball.xScale = var*0.01
        end
        if var*0.01 > ball.yScale then
        ball.yScale = var*0.01
        end
        
        print(var)
        end
elseif event.phase == "ended" or event.phase == "cancelled" then
        lastscalex = ball.xScale
        lastscaley = ball.yScale
        
        display.getCurrentStage():setFocus(nil)
 
end
end
 
 
ball:addEventListener("touch", drag_resize)

Thanks DarkConsoles!

That's very helpful and exactly what I envisioned for the initial growing. Now to figure out how to make it smaller again.

This will keep me busy over new years :)

Happy new year to all!
Alex

be sure to post the solution here if you find it out

happy new year!

Try this maybe...I don't know what your after but maybe
play with it or both to make things your way..:)

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
--
-- This may work for ya or you can play with it to get maybe what ya want..:)
-- it is really simple to understand and do
-- Have fun! Sharp1959 (Larry)
--
--
 
local cir_rd = 30
local circle_1 = nil
 
 
 
 
        circle_1 = display.newCircle(200, 200, cir_rd )
 
        
        function letsResizeNow(event)
 
                --use event.x on screen to tell us how to resize RADIUS (use cir_rd * 2 to get 60 for diameter)
                cir_rd = ((event.x - circle_1.x) + 60)
                
                --remove old circle
                circle_1:removeSelf()
                
                --redraw new(SIZED) circle same x and y different radius
                circle_1 = display.newCircle(200, 200, cir_rd)
                
                --Just because we what to change the color and see resize works
                circle_1:setFillColor(math.random (255), math.random (255),math.random (255))
        
        
        end
        
        
        Runtime:addEventListener( "touch", letsResizeNow )<code>
 
Have FUN!
Larry

@sharp1959, wow, its simple and awesome)

Just remember it is a Runtime Event

Runtime:addEventListener( "touch", letsResizeNow )

May have to play a litte to get circle touch event to work depending on what your looking for

Fantastic!

Thanks so much for your help!!!

Happy new year to all :)

Happy Newyear to you also, and BE safe!

Have Fun! :)

Larry

Yes, not too much Corona before driving ;)

views:1704 update:2012/1/3 13:02:13
corona forums © 2003-2011