My problem is quite unique..

I have this unique problem that I have the co-ordinate of different image to be placed but don't know how to use it to fix this at random to different fixed location.I had asked this query before but did not get any answer but hoping to get this time .

I thought of using math.random but did not solve my problem.Any Help please..

I'm not exactly sure what you are asking. It's going to be hard to advise with so little information.

It sounds to me like you have a set of images, and you have the x, y coordinates to draw the, but you want to draw them in a random order.

If this is the case, you need a "shuffle" routine. You have a table of images, and their X and Y's and then you randomize the array, then loop through the table now that the order has been randomized and you get the effect you're kind of describing.

Heheh,

Indeed: your description is not that easy to understand. Anyway, a wild guess of your problem and solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local table = {}
table[1].name = "image1.png"
table[1].Xpos = 32
table[1].Ypos = 100
 
table[2].name = "image2.png"
table[2].Xpos = 88
table[2].Ypos = 50
 
table[3].name = "image3.png"
table[3].Xpos = 100
table[3].Ypos = 250
 
myImage = "a global variable here"
 
local function randomImage()
  myImage = nil -- this line is just to make sure your previous image is deleted
  local randomNumber = math.random(#table)
 
  myImage = display.newImage(table[randomNumber].name, table[randomNumber].Xpos, table[randomNumber].Ypos)
end -- randomImage
 
timer.performWithDelay(1000, randomImage)
views:1427 update:2011/10/17 21:25:02
corona forums © 2003-2011