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
[lua]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)[/lua]
THANKS [import]uid: 51459 topic_id: 16237 reply_id: 316237[/import]