best way for displaying images on the bottom of the screen

I have a working program which has two sets of numbers 1-10 on the left and right side of the screen. If a player clicks on a number on the left side the program knows that you have only selected that number on the left side and displays it on the screen. If the player picks a number on the right side the program knows that the player has selected two numbers and to add those two numbers together. I was wondering how I can display some images on the bottom so that if a player picks a number they get to see a visual amount of that number. Like for instance if a player picks the number 5 the screen will display 5 images on the bottom of that number set. I had set up a table of postions for the images on the left side to see if I can get something working before I transfer over to the left side.. Heres the code I got so far:)

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
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 number1 = display.newImageRect("numbers.png",464,471)
         number1.x = 250; number1.y = 243
 
local number2 = display.newImageRect("numbers.png",464,471)
         number2.x = 750; number2.y = 253
        
local hitSpot = {}
 
local res, var1, var2 = 0,0,0
         
local numberText =  display.newText(string.format("Number: %02d", 0), 0, 0, native.systemFontBold, 40)
          numberText:setTextColor( 255,0,0 )
      numberText.x = 500;  numberText.y = 400
      
local number2Text =  display.newText(string.format("Number: %02d", 0), 0, 0, native.systemFontBold, 40)
          number2Text:setTextColor( 255,0,0 )
      number2Text.x = 500;  number2Text.y = 470
      
local answer =  display.newText(string.format("Answer: %02d", 0), 0, 0, native.systemFontBold, 40)
          answer:setTextColor( 33,31,32)
      answer.x = 500;  answer.y = 540
 
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 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 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
      numberText.text = string.format("Number: %02d", hitNumber)
      var1 = hitNumber
        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
  number2Text.text = string.format("Number: %02d", hit2Number)
  var2 = hit2Number
  res = tonumber(var1) + tonumber(var2)
  print("TOTAL " .. res)
  answer.text = string.format("Answer: %02d", res)      
        
end
 
number1:addEventListener("touch",numberSet1)
number2:addEventListener("touch",numberSet2)

Thanks Rob!! I will have a look!

Wow Rob this is perfect!! I can use this for my game too!!

THIS = AWESOME

Ok Rob this all makes sense when you - each image when you get hit and add each image when you get a extra life.. But in my case its a little more complicated.. if everything is connected to hitNumber theoretically can't I just set hitNumber = lives when a number is selected?

I tried this and nothing happend also I am having a little trouble figuring out how to display no images in the beginning and then showing the amount of images when something is selected.. :/

views:1656 update:2011/10/18 8:54:01
corona forums © 2003-2011