Hi guys, I have the following problem:
I have an object with a progress bar. Whenever the progress advances far enough, an additional square gets lit up.
--Initialization of 24 squares
--
self.bars = {}
local k = 0
for i=1,24 do
self.bars[i] = Geom.createRectAngle(0,0,10,10,0x115578)
self.bars[i]:setPosition(self.x+5+(i%6)*15, self.y+8+(k*15))
self:addChild(self.bars[i])
if i%6 == 0 then
k = k+1
end
end |
--Colortransforming of all available squares in the ENTER_FRAME event.
--self.framesElapsed is reset to zero once the progress reaches 100%
--
local prog = round((self.framesElapsed/self.framesNeeded)*#self.bars, 0)
if prog > 0 then
for i=1, prog do
self.bars[i]:setColorTransform(2,2,2,1)
end
else
for i=1, #self.bars do
self.bars[i]:setColorTransform(1,1,1,1)
end
end |
So far the mechanism works, but there is one bug.
Please have a look at my video I uploaded, you will get what I want to do and what's the problem:
The first square to be color transformed is always the SECOND one in a row.
To my understanding, it should be the first one, according to my code.
Instead, the first square in a row will be the last one which gets color transformed.
Is this some kind of special behaviour of lua I missed out on?
Thanks in advance
Comments
1->1
2->2
3->3
4->4
5->5
6->0
and then you increase k
so no wonder it goes in this order.
try this:
self.bars = {}
local k = -1
for i=0,23 do
if i%6 == 0 then
k = k+1
end
self.bars[i] = Geom.createRectAngle(0,0,10,10,0x115578)
self.bars[i]:setPosition(self.x+5+(i%6)*15, self.y+8+(k*15))
self:addChild(self.bars[i])
end
Likes: Holonist
Fragmenter - animated loop machine and IKONOMIKON - the memory game
edit: ah now i get it, sorry. the squares are actually misaligned in the first place.
gonna try what you say
I also had to write "self.bars[i+1]" instead of self.bars[i] so the second loop would be able to finish, too.
Fragmenter - animated loop machine and IKONOMIKON - the memory game