mouse down event

What I have on the screen is to sets of numbers 1-10 an image of a sun behind it. The two suns spin like two dials.. In the code it detects if user has let go of there mouse on any of the two numbers then adds them. Also what the code does is if you click on any number it will show that number visually with birds. For example if you click on 5 on one side it will show 5 birds on the bottom of the screen. Everything is working perfect I just want to add a special effect where the program knows that user has the mouse down and it is hovering over a number and changes the color of that number when it is highlighted

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
display.setStatusBar( display.HiddenStatusBar ) -- HIDE STATUS BAR
 
local screenW = display.contentWidth
local screenH = display.contentHeight
 
local BG = display.newImageRect("background.png", 1024, 768)
BG.x = screenW/2;  BG.y = screenH/2 
        
local birdIcons = {}
local bird2Icons = {}
local number1 = {}
local number2 = {}
 
local i
 
local t1 = {
        
        { x=310, y=178 },
        { x=340, y=220 },
        { x=340, y=270 },
        { x=305, y=312 },
        { x=258, y=328 },
        { x=203, y=315 },
        { x=165, y=280 },
        { x=165, y=228 },
        { x=185, y=181 },
        { x=249, y=160 }
}
 
local t2 = {
        
        { x=810, y=188 },
        { x=840, y=233 },
        { x=840, y=280 },
        { x=805, y=322 },
        { x=755, y=340 },
        { x=700, y=325 },
        { x=660, y=285 },
        { x=660, y=235 },
        { x=685, y=188 },
        { x=750, y=170 }
}
 
local bt1 = {
        
        { x = 60, y = 530 },
        { x = 120, y = 530 },
        { x = 180, y = 530 },
        { x = 240, y = 530 },
        { x = 300, y = 530 },
        { x = 60, y = 650 },
        { x = 120, y = 650 },
        { x = 180, y = 650 },
        { x = 240, y = 650 },
        { x = 300, y = 650 },
        
}
 
local bt2 = {
        
        { x = 700, y = 530 },
        { x = 760, y = 530 },
        { x = 820, y = 530 },
        { x = 880, y = 530 },
        { x = 940, y = 530 },
        { x = 700, y = 650 },
        { x = 760, y = 650 },
        { x = 820, y = 650 },
        { x = 880, y = 650 },
        { x = 940, y = 650 },
        
}
 
for i = 1, 10 do
        bird2Icons[i] = display.newImageRect("bird.png",59, 105)
        bird2Icons[i].x = bt2[i].x;  bird2Icons[i].y = bt2[i].y
        bird2Icons[i].isVisible = false
end
 
for i = 1, 10 do
        birdIcons[i] = display.newImageRect("bird.png",59, 105)
        birdIcons[i].x = bt1[i].x;  birdIcons[i].y = bt1[i].y
        birdIcons[i].isVisible = false
end
 
 
local function drawBirdImg(num)
        for i = 1, 10 do
                if i <= num then
                        birdIcons[i].isVisible = true
                else
                        birdIcons[i].isVisible = false
                end
        end
end
 
local function draw2BirdImg(num)
        for i = 1, 10 do
                if i <= num then
                        bird2Icons[i].isVisible = true
                else
                        bird2Icons[i].isVisible = false
                end
        end
end
 
local res, var1, var2 = 0,0,0
 
local sun1 = display.newImageRect("numbers.png",464,471)
         sun1.x = 250; sun1.y = 243
 
local sun2 = display.newImageRect("numbers.png",464,471)
         sun2.x = 750; sun2.y = 253
         
local text1 =  display.newText(string.format("Number: %02d", 0), 0, 0, native.systemFontBold, 40)
          text1:setTextColor( 255,0,0 )
      text1.x = 500;  text1.y = 400
      
local text2 =  display.newText(string.format("Number: %02d", 0), 0, 0, native.systemFontBold, 40)
          text2:setTextColor( 255,0,0 )
      text2.x = 500;  text2.y = 470
      
local answer =  display.newText(string.format("Answer: %02d", 0), 0, 0, native.systemFontBold, 40)
          answer:setTextColor( 31,31,32)
      answer.x = 500;  answer.y = 540
      
for i = 1, 10 do
number1[i] = display.newText(  i, 0, 0, native.systemFontBold, 40)
number1[i].x = t1[i].x;  number1[i].y = t1[i].y
 
number1[i]:setTextColor( 255,0,0)
end
 
for i = 1, 10 do
number2[i] = display.newText(  i, 0, 0, native.systemFontBold, 40)
number2[i].x = t2[i].x;  number2[i].y = t2[i].y
 
number2[i]:setTextColor( 255,0,0)
end
 
function hitTestObject(point, xMin, yMin, xMax, yMax)
        local xInside = point.x >= xMin and point.x <= xMax 
        local yInside = point.y >= yMin and point.y <= yMax
        return (xInside and yInside) 
end
 
 
local x0 , y0, x1, x2
 
local function angleBetween(a, b)       --returns angle between 2 vectors a and b
        local angleA = math.deg(math.atan(a.y/a.x))
        local angleB = math.deg(math.atan(b.y/b.x))
        
        print(angleB - angleA)
        return  (angleB - angleA)
end
 
local function turn(e)
        if e.phase == "began" then
                x0 = e.x
                y0 = e.y
     
                
        elseif e.phase == "moved" then
                x1 = e.x
                y1 = e.y
                
       print ("mouse down")
                
                local v1 = {x=x0-e.target.x, y=y0-e.target.y}
                local v2 = {x=x1-e.target.x, y=y1-e.target.y}
                
                local angle = angleBetween(v1,v2)
                
                if (angle > 90) then
                        angle = angle - 180
                                elseif (angle < -90) then
                 angle = angle + 180
                end
                
                e.target.rotation = e.target.rotation + angle
                
                x0 = x1
                y0 = y1
        
        end
 
end
 
 
local function numberSet1(e)            
        for i=1,#t1  do
                hitNumber = 0
                local outCome = hitTestObject(e, t1[i].x - 20, t1[i].y - 22, t1[i].x + 20, t1[i].y + 22)
                if (outCome == true) then
                        hitNumber = i 
                                 break  --used to stop looping through the other items
                end 
        end
 
      text1.text = string.format("Number: %02d", hitNumber)
      var1 = hitNumber
      drawBirdImg(var1)
        res = tonumber(var1) + tonumber(var2)
        print("TOTAL " .. res)  
          answer.text = string.format("Answer: %02d", res)      
        
end
 
local function numberSet2(e)
for i=1,#t2 do
        hit2Number = 0
        local outCome = hitTestObject(e, t2[i].x - 20, t2[i].y - 22, t2[i].x + 20, t2[i].y + 22)
                if (outCome == true) then
                        hit2Number = i
                break  --used to stop looping through the other items
    end 
end
  text2.text = string.format("Number: %02d", hit2Number)
  var2 = hit2Number
  draw2BirdImg(var2)    
  res = tonumber(var1) + tonumber(var2)
  print("TOTAL " .. res)
  answer.text = string.format("Answer: %02d", res)      
        
end
 
sun1:addEventListener("tap",numberSet1)
sun2:addEventListener("tap",numberSet2)
sun1:addEventListener("touch",turn) 
sun2:addEventListener("touch",turn)
views:1135 update:2011/10/19 8:59:29
corona forums © 2003-2011