I'm trying to check a carried objects position so that its sprite will change to a falling effect when it lands on a hole. However, I'm having an issue where the effect will happen for every hole tile it goes over and I only want the effect to happen on the tile that it lands on not every tile that it goes over while being thrown.
It will be possible with Solarus 1.6, with a new event function, and I think Christopho has already coded it. Chris has been working very hard, even harder than adamantium, on the engine, and from the more than 100 issues that there were before, less than 40 remain to do. That means Solarus 1.6 is coming very soon...
Hello, I did something to create a "non destructible objet" using the metatable of destructible. When the carried object stop its movement, a new destructible is created instead, at the "landing"position. It's like the object can be carried and thrown again and again.
function destructible_meta:on_lifting()
local map = self:get_map()
local hero = self:get_map():get_hero()
local sprite = self:get_sprite():get_animation_set()
local name = self:get_name()
local entity_state = nil
if name ~= nil then
sol.timer.start(map, 10, function()
if hero:get_state() == "lifting" then
entity_state = hero:get_state()
end
if entity_state == "lifting" and hero:get_state() == "carrying" then
entity_state = hero:get_state()
end
if entity_state == "carrying" and hero:get_state() == "free" then
entity_state = hero:get_state()
for entity in map:get_entities_by_type("carried_object") do
function entity:on_movement_changed(movement)
local x,y,layer = entity:get_position()
if not map:has_entities(name) then
if name:match("^non_destructible") then
map:create_destructible{name = name, layer = layer, x=x, y=y, sprite = sprite}
entity:remove()
end
end
end
end
return false
end
return true
end)
end
end
In your case, you have to test the position with the ground's one and if it's a hole, change the animation with the falling one. (and of course, not create the new object !!)
For one time I am not asking for help, I'm glad to help someone else ! ;D
There is another example in the project XD2. (The metal ball.)