thank you very much my dear Sir
could you also be of help in how to load the numbers of enemies on screen cause i havnt quite figured that out yet [import]uid: 215264 topic_id: 35900 reply_id: 142705[/import]
- Put all of your enemies in a displayGroup.
[code] – make the group just once, at the beginning
local enemyGroup = display.newGroup()
– whenever you make an enemy, insert it
enemyGroup:insert(myEnemy)
– anytime you want to know how many objects are in enemyGroup:
print("# of enemies:", enemyGroup.numChildren)
– or show on screen
local enemyCount = display.newText(enemyGroup.numChildren, 0, 0, native.systemFont, 18)
– the onscreen count will never change unless you update it, though, so periodically you will want to use:
enemyCount.text = enemyGroup.numChildren[/code] [import]uid: 41884 topic_id: 35900 reply_id: 142747[/import]
Thank you would you also help me by answering another question
Let’s say I have green, red and black. And I want it to be randomized each time a new enemy comes on screen. How will I perform this? [import]uid: 215264 topic_id: 35900 reply_id: 142760[/import]
If it’s just a color, then think about what you just wrote and break it down into pieces:
colors : You have 3 colors, so make a table of them.
local colors = {}
colors[1] = { 0, 255, 0 } -- green (rGb)
colors[2] = { 255, 0, 0 } -- red (Rgb)
colors[3] = { 0, 0, 0 } -- black
random : You want to randomly pick a color. So you basically want to pick a random number between 1 and 3 (the total number of colors.) Well, #table is the total size of a table, so…
local randomColor = colors[math.random(#colors)]
The trick here is that :setFillColor doesn’t accept tables - it wants three individual numbers. So you need to “unpack” it.
myEnemy:setFillColor( unpack(randomColor) )
Breaking down what you want to do into little pieces is the very essence of coding, no matter what your programming language is. Think about those chunks and you’ll have a much easier time figuring out how to do something. [import]uid: 41884 topic_id: 35900 reply_id: 142761[/import]
Thanks but I made a mistake the green red and black are the enemy colors
What I need is a method to randomly display them coming from the top down. ( I am not using the physics engine)
I can do that part, make them come from one point and walk to another what I need to do is
From a spite sheets choose random colors to come on screen
So I got a sprite sheet with all those colors I just need a way of randomizing the colors to come on screen and also more of them as the score inceases
[import]uid: 215264 topic_id: 35900 reply_id: 142764[/import]