Game Development Reference
In-Depth Information
end
if (self.enabled == false) then return end
--track to see if we have a valid target
if (self.gameLayer.selectedGem ~= nil and
self.touchDown == true) then
self.gameLayer.selectedGem:setPosition(
touch.x -
self.gameLayer.gemsContainer:getPositionX(),
touch.y -
self.gameLayer.gemsContainer:getPositionY())
local touchedGem = self:findGemAtPosition
(touch)
if (touchedGem.gem ~= nil and
self:isValidTarget(touchedGem.x, touchedGem.y, touch)
== true ) then
self:selectTargetGem(touchedGem)
end
end
end
We run most of the same logic as we did with onTouchDown . We move the se-
lectedGem object until a suitable target gem is identified, and then we pick the
second one as the target. This is when the swap happens. Let's do that now.
8. First, the logic that sets our selected gem:
function GridController:selectStartGem (touchedGem)
if (self.gameLayer.selectedGem == nil) then
self.gameLayer.selectedGem = touchedGem.gem
self.gameLayer.targetGem = nil
self.gameLayer.targetIndex = nil
touchedGem.gem:setLocalZOrder(constants.Z_SWAP_2)
self.gameLayer.selectedIndex = {x =
touchedGem.x, y = touchedGem.y}
self.gameLayer.selectedGemPosition = {x =
touchedGem.gem:getPositionX(),
y =
touchedGem.gem:getPositionY()}
Search WWH ::




Custom Search