Hello,
I am making a 20x20 square grid with squares that are 40x40 pixels.
Here is my code right now:
local a
local b = -1
local x
local y = -1
for h = 0, 20 do
b = b + 1
a = b * 40
for i = 0, 20 do
y = y + 1
x = y * 40
local square = Bitmap.new(Texture.new("images/square.png"))
square:setPosition(x,a)
self:addChild(square)
end
end |
However, I am only getting one row of squares. Here is my reasoning behind the code. The first loop let's call h and the second loop lets call i. So, I thought that once h has looped once i has looped 20 times, thus making 20 squares at the y coordinate of 0. Then when h loops again the y coordinate or a is added 40 pixels. Then i would loop another 20 times , thus making 20 squares at the y coordinate of 40. Then it keeps going until h has looped twenty times and i has looped 400 times. Since I am only getting one row of 20 squares, I don't get why it isn't looping more times and adding 40 to the y coordinate each time h loops.
So, please help me understand why my code isn't working the way I intended. Thank you very much!!
P.S. I didn't get any errors.
I am a programming noobie, so thanks in advance for helping me out and answering my questions!
Comments
0 0 0 0
_ _ _ _ 0 0 0 0
_ _ _ _ _ _ _ _ 0 0 0 0
etc.
They are probably getting outside the screen or something.
So I guess something like that:
Funny that you mentioned it, while I was just working on one of components called GridView for new GameTemplate
Likes: QuasarCreator
I also wanted to say that your GameTemplate has helped me so much and probably every other beginner out there, so thanks. >-