Simple pool flaw? help

9 replies [Last post]
brian0405
User offline. Last seen 3 days 10 hours ago. Offline
Joined: 21 Jan 2011

I have been using the simple pool code, and i might have discovered a flaw. As you continue to click on the ball the rotation of the green spinner around the ball continues to go faster. Every time you click on it it speeds up alittle more. This causes problems when you use director.

Does anyone know of a simple solution to fix this problem?

Replies

Swello Applications's picture
Swello Applications
User offline. Last seen 6 weeks 5 days ago. Offline
Joined: 27 Aug 2011

Not sure exactly what you mean, but I think you may have forgotten to remove an event listener....Post some code and I will take a look.

brian0405
User offline. Last seen 3 days 10 hours ago. Offline
Joined: 21 Jan 2011

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
        -- Shoot the cue ball, using a visible force vector
        local function cueShot( event )
                local t = event.target
        
                local phase = event.phase
                if "began" == phase then
                        display.getCurrentStage():setFocus( t )
                        t.isFocus = true
                        
                                -- Stop current cueball motion, if any
                        t:setLinearVelocity( 0, 0 )
                        t.angularVelocity = 0   
        
                        target.x = t.x
                        target.y = t.y
                
                        startRotation = function()
                                target.rotation = target.rotation + 1
 
                        end
                                
                        Runtime:addEventListener( "enterFrame", startRotation )
                        
                        local showTarget = transition.to( target, { alpha=0.4, xScale=0.2, yScale=0.2, time=200 } )
                        myLine = nil
 
                elseif t.isFocus then
                        if "moved" == phase then
                        
                                if ( myLine ) then
                                        myLine.parent:remove( myLine ) -- erase previous line, if any
                                end
                                myLine = display.newLine( t.x,t.y, event.x,event.y )
                                myLine:setColor( 255, 255, 255, 50 )
                                myLine.width = 8
 
                        elseif "ended" == phase or "cancelled" == phase then
                                display.getCurrentStage():setFocus( nil )
                                t.isFocus = false
                                
                                local stopRotation = function()
                                        
                                        Runtime:removeEventListener( "enterFrame", startRotation )
                                end
                        
                                local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )
                                
                                if ( myLine ) then
                                        myLine.parent:remove( myLine )
                                end
                        
                                -- Strike the ball!
                                t:applyForce( ( event.x - t.x ), ( event.y - t.y ), t.x, t.y )
                                audio.play(hitsound)
                        
                                
                        end
                end
 
                -- Stop further propagation of touch event
                return true
        end

Everytime you hit the "cueball", "target"(an image that spins"), spins + 1. This gives it the rotation that you see in the simple pool. But over time if you keep constantly clicking the "cueball" the "target" spins faster. So after you hit it 10 or so times, you can see a huge diffrence in the speed of the rotation. This is causing problems with director. Any ideas to help?

Swello Applications's picture
Swello Applications
User offline. Last seen 6 weeks 5 days ago. Offline
Joined: 27 Aug 2011

this works perfectly for me...Are you using a director...You can send your project here (kurtbringsjord@swelloapplications.com) If you'd like.

brian0405
User offline. Last seen 3 days 10 hours ago. Offline
Joined: 21 Jan 2011

I think i found why the director wasnt working, but is there a way to keep the spinning constant every click you do?

Swello Applications's picture
Swello Applications
User offline. Last seen 6 weeks 5 days ago. Offline
Joined: 27 Aug 2011

You are saying that the spinning thing in pool plus is spinning faster and faster every time you click it...Although when I test the Pool Plus Game, it does not.

brian0405
User offline. Last seen 3 days 10 hours ago. Offline
Joined: 21 Jan 2011

I guess this could be a problem!

I tried two links

https://github.com/ansca/Simple-Pool

and the simple pool on this

http://developer.anscamobile.com/sample-code/platform-specific

If you click the ball about 20 times without hitting the pockets the ball goes really fast, maybe its just me!

Swello Applications's picture
Swello Applications
User offline. Last seen 6 weeks 5 days ago. Offline
Joined: 27 Aug 2011

Weird, works well for me... What are you trying to do with it?

brian0405
User offline. Last seen 3 days 10 hours ago. Offline
Joined: 21 Jan 2011

Im just trying it with the corona simulator, Version 2011.591 (2011.8.2).

clarkj99
User offline. Last seen 2 weeks 1 day ago. Offline
Joined: 2 Feb 2012

I'm having the same problem. It's as if the event listener won't be removed if you tap the screen too quickly.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.