hi there, I’m looking into your engine and I have a few questions, I hope for your help.
in my game fruits fall from above, i want that if two same fruits collide then they will turn into the next fruit
here I create fruits on click
local camera = require "orthographic.camera"
local fruit_list = {"apple", "pear", "orange", "grape", "strawberry", "blueberry"}
function spawnFruit()
local random_index = math.random(1, #fruit_list)
local fruit = fruit_list[random_index]
return fruit
end
function init(self)
msg.post(".", "acquire_input_focus")
self.pos = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local pos = vmath.vector3(action.x, action.y, 0)
local camera_id = hash("/camera")
self.pos = camera.screen_to_world(camera_id, pos)
local item_id = factory.create("#factory", self.pos)
local url = msg.url(item_id)
url.fragment = "sprite"
local random_fruit = spawnFruit()
sprite.play_flipbook(url, random_fruit)
msg.post(item_id, "created")
end
end
and here I’m trying to push fruits, but I can’t
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
if message.other_id == hash("/walls") then
return
else
local url = msg.url(message.other_id)
url.fragment = "sprite"
local sprite_name = go.get(url, "animation")
print(sprite_name)
if sprite_name then
local fruit_list = {"apple", "pear", "orange", "grape", "strawberry", "blueberry"}
local index = 1
for i, fruit in ipairs(fruit_list) do
if fruit == sprite_name then
index = i
break
end
end
local next_index = (index % #fruit_list) + 1
local next_fruit = fruit_list[next_index]
sprite.play_flipbook(url, hash(next_fruit))
-- factory.create("/cubeFactory#factory", vmath.vector3(0, 0, 0), nil, {sprite = next_fruit})
else
return
end
-- sprite.play_flipbook(url, hash("grape"))
end
end
end
I came from Unity and there I could understand in different ways what object I encountered, how to do this in Defold?
For example, I want to understand that a pear collided with a pear, which means that they then stack and turn into an orange.
How can I tell if one sprite has collided with another and their sprites are equal? how to destroy colliding objects and spawn a sprite with a higher grade in their place?