setReferencePoint error with director (SOLVED!)

I got this function:

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
function printTime()
                secondsEffect()
                secondsPast = secondsPast+1
                
                if secondsPast == 60 then
                        minutesEffect()
                        minutesPast = minutesPast+1
                        secondsPast = 0
                end
                
                seconds.text = secondsPast
                
                seconds:setReferencePoint(display.CenterLeftReferencePoint)
                seconds.x = display.contentWidth/2 + 12
                
                minutes.text = minutesPast
                minutes:setReferencePoint(display.CenterRightReferencePoint)
                minutes.x = display.contentWidth/2 - 12
                
                
        end
        function startTimer()
        timer.performWithDelay( 1000, printTime, 0)
        end
        
        startTimer()

I tried the below code am not getting any error on that

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
        local secondsPast = 1
    local minutesPast = 0
        local seconds = display.newText("0",120,120,nil,25)
    local minutes = display.newText("0",150,120,nil,25)
 
    seconds:setReferencePoint(display.CenterLeftReferencePoint)
    seconds.x = display.contentWidth/2 + 12
    
    minutes.text = minutesPast
    minutes:setReferencePoint(display.CenterRightReferencePoint)
    minutes.x = display.contentWidth/2 - 12
 
 
function printTime()
                        --secondsEffect()
                        secondsPast = secondsPast+1
 
                        if secondsPast == 60 then
                               -- minutesEffect()
                                minutesPast = minutesPast+1
                                secondsPast = 0
                        end
 
                        seconds.text = secondsPast
 
                        seconds:setReferencePoint(display.CenterLeftReferencePoint)
                        seconds.x = display.contentWidth/2 + 12
 
                        minutes.text = minutesPast
                        minutes:setReferencePoint(display.CenterRightReferencePoint)
                        minutes.x = display.contentWidth/2 - 12
 
 
end
function startTimer()
        timer.performWithDelay( 1000, printTime, 0)
end
 
startTimer()

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
module(..., package.seeall)
function new()
local localGroup = display.newGroup()
kolon = display.newText(":", 50,50, system.defaultFont, 50)
kolon:setTextColor(250,250,250)
kolon:setReferencePoint(display.CenterReferencePoint)
kolon.x = display.contentWidth/2
kolon.y = display.contentHeight/1.24
localGroup:insert(kolon)
 
secondsPast = 0
minutesPast = 0
 
seconds = display.newText(secondsPast,50,50,system.defaultFont, 50)
seconds:setReferencePoint(display.CenterLeftReferencePoint)
seconds.x = kolon.x + 12
seconds.y = display.contentHeight/1.24
localGroup:insert(seconds)
 
minutes = display.newText(minutesPast,50,50,system.defaultFont, 50)
minutes:setReferencePoint(display.CenterRightReferencePoint)
minutes.x = kolon.x - 12
minutes.y = display.contentHeight/1.24
 
localGroup:insert(minutes)
 
function secondsEffect()
        transition.to(seconds,{time=100, y=seconds.y-40 })
        transition.to(seconds,{time=100, delay=50, y=seconds.y})
end
 
function minutesEffect()
        transition.to(minutes,{time=100, y=minutes.y-40 })
        transition.to(minutes,{time=100, delay=50, y=minutes.y})
end
 
function printTime()
                secondsEffect()
                secondsPast = secondsPast+1
                
                if secondsPast == 60 then
                        minutesEffect()
                        minutesPast = minutesPast+1
                        secondsPast = 0
                end
                
                seconds.text = secondsPast
                
                seconds:setReferencePoint(display.CenterLeftReferencePoint)
                seconds.x = display.contentWidth/2 + 12
                
                minutes.text = minutesPast
                minutes:setReferencePoint(display.CenterRightReferencePoint)
                minutes.x = display.contentWidth/2 - 12
                
                
        end
        function startTimer()
        timer.performWithDelay( 1000, printTime, 0)
        end
        
        startTimer()
        return localGroup
end

code looks fine...
can you do something...
put a print statement after function new() and see whether the program is reaching that scene..

Tested it and it gets to next scene before I get the error.

I can't regenerate the error...
can you try commenting the lines with SetReferencePoint let's see what happens.

What do you mean?

I commented the lines and now it doesn't give an error but:

The reference point is wrong.

When it switches scene and you got back to it, the time text jumps away and it is there for more than 3 seconds.

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
module(..., package.seeall)
function new()
local localGroup = display.newGroup()
kolon = display.newText(":", 50,50, system.defaultFont, 50)
kolon:setTextColor(250,250,250)
kolon:setReferencePoint(display.CenterReferencePoint)
kolon.x = display.contentWidth/2
kolon.y = display.contentHeight/1.24
localGroup:insert(kolon)
 
secondsPast = 0
minutesPast = 0
 
seconds = display.newText(secondsPast,50,50,system.defaultFont, 50)
seconds:setReferencePoint(display.CenterLeftReferencePoint)
seconds.x = kolon.x + 12
seconds.y = display.contentHeight/1.24
localGroup:insert(seconds)
 
minutes = display.newText(minutesPast,50,50,system.defaultFont, 50)
minutes:setReferencePoint(display.CenterRightReferencePoint)
minutes.x = kolon.x - 12
minutes.y = display.contentHeight/1.24
 
localGroup:insert(minutes)
 
function secondsEffect()
        if seconds.y then
        transition.to(seconds,{time=100, y=seconds.y-40 })
        transition.to(seconds,{time=100, delay=50, y=seconds.y})
        end
end
 
function minutesEffect()
        if minutes.y then
        transition.to(minutes,{time=100, y=minutes.y-40 })
        transition.to(minutes,{time=100, delay=50, y=minutes.y})
        end
end
 
function printTime()
                secondsEffect()
                secondsPast = secondsPast+1
                
                if secondsPast == 60 then
                        minutesEffect()
                        minutesPast = minutesPast+1
                        secondsPast = 0
                end
                
                seconds.text = secondsPast
                
        --      seconds:setReferencePoint(display.CenterLeftReferencePoint)
                seconds.x = display.contentWidth/2 + 12
                
                minutes.text = minutesPast
        --      minutes:setReferencePoint(display.CenterRightReferencePoint)
                minutes.x = display.contentWidth/2 - 12
                
                
        end
        function startTimer()
        timer.performWithDelay( 1000, printTime, 0)
        end
        
        function onTimer()
                director:changeScene("mainmenu")
        end
        
        timer.performWithDelay( 3000, onTimer,1)
        
        startTimer()
        return localGroup
end

I changed the text objects to labels instead:

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module(..., package.seeall)
function new()
local localGroup = display.newGroup()
local ui = require ("ui")
 
 
--Kolon label
local kolon = ui.newLabel  {
text =  ":",
        textColor = {255, 255, 255, 255},
        size = 50,
        font = "helvetica",
        align = "center",
        bounds = {0, 0, 0, 0},
};
kolon.x = display.contentWidth/2
kolon.y = display.contentHeight/1.24
localGroup:insert(kolon)
 
 
secondsPast = 0
minutesPast = 0
 
--Seconds label
local seconds = ui.newLabel  {
text =  secondsPast,
        textColor = {255, 255, 255, 255},
        size = 50,
        font = "helvetica",
        align = "left",
        bounds = {0, 0, 0, 0},
};
seconds.x = kolon.x + 12
seconds.y = display.contentHeight/1.24
localGroup:insert(seconds)
 
 
local minutes = ui.newLabel  {
text =  minutesPast,
        textColor = {255, 255, 255, 255},
        size = 50,
        font = "helvetica",
        align = "right",
        bounds = {0, 0, 0, 0},
};
minutes.x = kolon.x - 12
minutes.y = display.contentHeight/1.24
localGroup:insert(minutes)
 
function secondsEffect()
        if seconds.y then
        transition.to(seconds,{time=100, y=seconds.y-40 })
        transition.to(seconds,{time=100, delay=50, y=seconds.y})
        end
end
 
function minutesEffect()
        if minutes.y then
        transition.to(minutes,{time=100, y=minutes.y-40 })
        transition.to(minutes,{time=100, delay=50, y=minutes.y})
        end
end
 
function printTime()
                secondsEffect()
                secondsPast = secondsPast+1
                
                if secondsPast == 60 then
                        minutesEffect()
                        minutesPast = minutesPast+1
                        secondsPast = 0
                end
                
                seconds:setText(secondsPast)
                
                minutes:setText(minutesPast)
                
                
        end
        function startTimer()
        timer.performWithDelay( 1000, printTime, 0)
        end
        
        function onTimer()
                director:changeScene("mainmenu")
        end
        
        timer.performWithDelay( 3000, onTimer,1)
        
        startTimer()
        return localGroup
end

The problem is that the timer doesn't stop quickly enough.

Got it working with http://jonbeebe.tumblr.com/post/2439016279/how-to-use-the-new-time-functions

Now i got a game.cancelAllTimers() right before the director:changeScene("mainmenu")

Thank god for Jonathan Beebe :D

views:1915 update:2011/9/28 9:01:40
corona forums © 2003-2011