Z-order of factory objects (SOLVED)

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.

image

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
1 Like

oh dear… i was confusing message_id with message.id…

function on_message(self, message_id, message, sender)
	if message_id == cursor.OVER then
		print("Cursor over", message.id, message.group, message.x, message.y)
2 Likes

So it’s it working now? I do recall adding some logic related to the z-value of the things under the cursor.

yes. btw i noticed that the factory incremented the z-position for object a little bit

If you don’t specify a position when calling factory.create() the spawned object will get the same position as the game object with the factory component.

before i did what is above ( the small manual increment of the z-pos)
i printed out the z-positions of the cards i spawned with the factory, and they were apparently automatically incremented - maybe because they were overlapping- like this:
0.0000000001
0.0000000001215
0.00000000013…

don’t know maybe it’s me or a bug.

There is no such logic in the engine. But I’m sure there’s an explanation. If you share a small repro case I can take a look and try to figure out what’s going on.

1 Like

i’d love to but i just tried to it but can’t reproduce it anymore.
too bad…
never mind.

thanks though.