I have also come across an issue with the two separate images moving a very different speeds, even while set to the same initial speed. The 'order' piece on the left moves much slower than the chaos piece. It doesn't matter which one I start to move first, it's always the same result.
Hi I looked at the code and testing it on the battle board I think I have found the bug.
Looks like the same 'piece' gets parented by several containers. Here's the problematic code:
- Code: Select all
if currentType == self.FIRE then
tile = self:getTile("Fire");
elseif currentType == self.AIR then
tile = self:getTile("Air");
elseif currentType == self.WATER then
tile = self:getTile("Water");
elseif currentType == self.EARTH then
tile = self:getTile("Earth");
elseif currentType == self.ORDER then
self.gamePieceOrder = GamePiece ( self.gamePieceOrder.imgPath, self.gamePieceOrder.imgFile, self.cellWidth / 2, i, j, self.gamePieceOrder.side )
piece = self.gamePieceOrder
elseif currentType == self.CHAOS then
self.gamePieceChaos = GamePiece ( self.gamePieceChaos.imgPath, self.gamePieceChaos.imgFile, self.cellWidth / 2, i, j, self.gamePieceChaos.side )
piece = self.gamePieceChaos
end
if piece then
self:add_child( piece )
end
Basically, the piece object gets added as a child to a number of other containers.
Therefore, each of those parent containers calls "redraw" in the child piece thus moving both pieces at arbitrary speed.
Make sure you insesrt the following line at the beginning of the block of code above:
- Code: Select all
local piece = nil
There really should be an assertion to prevent this in the GUI module. Funny enough, I added such an assertion a couple of weeks ago in the latest non-public versions (not out on BitBucket yet). So, it might be a good idea to add the assertion by modifying a couple of functions in ContainerG (extensions/lua/gui/container.lua):
- Code: Select all
ContainerG.add_child = function(self, child)
assert(child, "Child node is nil")
table.insert(self.objects, child)
assert(child.parent == nil, "Child already parented by another container")
child.parent = self
self.node:add_child(child.node)
end
ContainerG.remove_child = function(self, child)
assert(child, "Child node is nil")
if self.focus == child then
self.focus = nil
self.exclusive = false
end
if self.hover == child then
self.hover = nil
end
local i = self:get_child(child)
assert(i, "Child node is not parented by this container")
base.table.remove(self.objects, i)
self.node:remove_child(child.node)
child.parent = nil
end
Once you get that settled, you may notice that both pieces are moving at a much slower speed.
This is actually the 'correct' behavior since you have the speed set to 1 which means 1px per second.
Also, I should mention again that when a key is held down for over half a second, "key_command" gets called every 5 ms (in practice it's more like every 16 ms).
This is not a problem given your code (since you're not actually moving the pieces during "key_command") but I'm just reminding you that the function is called repeatedly while "repeated keystrokes" are on.
Not sure what might be causing the font issue. Maybe Phil will have something to say since he actually works on the engine itself. What's your videocard by the way?
