I have a gui.pick_node call which isn’t working, and I can’t figure out why.
I’m trying to program solitaire to learn about game design with defold. I am using the Druid gui asset. Here is the code that is breaking:
-- When a card drag ends, check if it was released over any KingZone.
card.component.on_drag_end:subscribe(function(dx, dy, touch)
local cardPos = gui.get_position(card.node)
for _, kingZone in ipairs(self.kingZones) do
if gui.pick_node(kingZone.node, cardPos.x, cardPos.y) then
if kingZone:place_card(card) then
return -- Card was successfully placed.
end
end
end
end)
When I start up the game and release a playing card over a king zone, nothing happens.
Things I have tried: I put print statements all over the place. I confirmed that the x,y coordinates agree, an example:
card coords: vmath.vector3(-302.66668701172,169.66668701172, 0)
zone coords: vmath.vector3(-300, 141, 0)
zone size: vmath.vector3(92, 128, 0)
These seem to confirm that the card is being dropped over the zone, and yet pick_node still returns false. I tried using the screen positions, and confirmed that the screen positions also put the card over the zone. I checked that the zone node was enabled, I checked its parent, I checked the scale (1,1,1) and the pivot (0). The weirdest part of this to me is that this code used to work–I had cards and zones in different gui scenes at one point and did this check by passing a message between them and it worked then; now they are in the same gui scene, no other big changes were made, but pick_node doesn’t work anymore.
I read the other threads I could google about pick_node not working, but none of them seem to apply to my scenario. Any insight as to what might be going wrong would be appreciated!