As part of my Defold journey, I try to make a Flappy Bird clone. I’m spawning 2 post (like pipes) game objects (upper and lower). They are both under a parent named pair. pair is the only game object of a collection file.
My main character, a cat, detects the collisions:
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
local parent = go.get_parent(message.other_id)
if message.other_id == hash("/roof") then
hit_roof(message, self)
elseif message.other_id == hash("/water") then
gameover(self)
elseif message.other_id == hash("/collection0/upper") then
gameover(self)
end
end
end
Initially I coded:
elseif message.other_id == hash("/upper") then
but doesn’t work. Then I coded:
elseif message.other_id == hash("/collection0/upper") then
It worked but only for the first post. Succeeding posts have the /collection1..2..3..etc.
Here’s how I spawn the posts:
local function spawn(self)
local y_min = 568 - 225
local y_max = 568 + 225
local y_random = math.random(y_min, y_max)
local p = vmath.vector3(770, y_random, 1.1)
local g = collectionfactory.create("#factory", p)
local pair_id = g[hash("/pair")]
table.insert(self.spawned_posts, pair_id)
msg.post(pair_id, "register", { spawner = go.get_id() })
print("spawned posts: " .. #self.spawned_posts)
end
Here’s how the collection file looks like:
And here’s the main collection:
In summary, how do I correctly check whether the cat collided with any of the spawned posts (since each spawn gives the id prefix /collectionN?


