hi,
i have a factory producing card-gameobjects:
for i=2,14 do
p.x=(i-1)*80
p.z=p.z+0.001
local id = factory.create("#cardfactory", p, nil, { suit = 3, rank=i })
[...]
the cards have just one sprite and a collisionobject.
the sprites’ z koordinate is 0, and you can see above that i give the gameobjects different z coordinates, so they overlap nicely.
i use defold-input extension with the cursor script, to be able to drag cards.
on cursor over i animate the y-coordinate of the card a little higher. (like hearthstone)
on cursor out i animate back to the original position.
now when i drag a card over the other cards, to the left, i get no cursor over events at the other cards.
when i drag a card to the right, i get them. the cards to the right have a higher z-coordinate.
i’ll just post my whole card.script here. could you look if you see some obvious mistakes?
maybe it’s smarter to have a main game hand controller handle that only one card is animated at all times, and pass messages to the cards what they should do. i tried this but ran into problems that in controller::on_message i got a message from a card but when i tried to send a message to the same card back, the message_id which contained the cardid suddenly contained the clickevent, ie. ‘pressed’, which resultet in a warning or error that the engine couldn’t find the object ‘pressed’… very weird!
local cursor = require "in.cursor"
go.property("suit", 1)
go.property("rank", 2)
function init(self)
-- array auto indices start with 1 !!!!
self.suitnames= {"club","diamond","heart","spade"}
self.cardnames={"dummy","2","3","4","5","6","7","8","9","10", "J","Q","K","A"}
msg.post("#sprite", "play_animation", {id = hash("96px-Playing_card_"..self.suitnames[self.suit]..
"_"..self.cardnames[self.rank]..".svg")})
self.init_pos= go.get_position()
self.playable=true
self.isclicked=false
end
function on_message(self, message_id, message, sender)
if message_id == hash("reset") then
print("card: reset")
elseif message_id==hash("toboard") then
print("card: played toboard")
self.playable=false;
elseif message_id == cursor.PRESSED then
self.isclicked=true
local p=go.get_position()
local s=go.get_position("#sprite")
print("card: played toboard, z:",p.z," sprite:",s.z)
elseif message_id == cursor.DRAG_START then
print("card: dragstart")
local p=go.get_position()
p.z=1
go.set_position(p) -- this seems not to work
elseif message_id == cursor.RELEASED then
self.isclicked=false
print("Released", message.id, message.group)
local p=go.get_position(message.id)
if p.y > 220 then
self.playable=false;
else
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, self.init_pos, go.EASING_OUTEXPO, 0.5, 0, landed)
end
elseif message_id==cursor.OVER and self.playable and (self.isclicked==false) then
local p=go.get_position()
p.y=p.y+30
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, p, go.EASING_OUTQUAD, 0.1)
elseif message_id==cursor.OUT then
if self.playable then
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, self.init_pos, go.EASING_OUTQUAD, 0.1)
end
end
--elseif message_id == hash("cursor_out") then
end