Okay, I think I have a solution. For all those who are facing a similar problem:
In my level handler I set the current level_id and which spawn_point (object name) should be taken. I pass this as a message to the player. I then use the spawn (game) object ID to get the position and then set the player to the same position.
Level Handler:
function init(self)
-- Input Focus muss durchgereicht werden
msg.post(".", "acquire_input_focus")
msg.post("levels#overworld", "load")
constants.set_level_id("overworld")
spawn_point = "sp_game_entry"
end
function final(self)
msg.post(".", "release_input_focus")
end
function on_message(self, message_id, message,sender)
if message_id == hash("level_overworld") then
constants.set_level_id("overworld")
spawn_point = "sp_osteria_out"
msg.post("levels#osteria", "unload")
msg.post("levels#overworld", "load")
elseif message_id == hash("level_osteria") then
constants.set_level_id("osteria")
spawn_point = "sp_osteria_in"
msg.post("levels#overworld", "unload")
msg.post("levels#osteria", "load")
elseif message_id == hash("proxy_loaded") then
msg.post(sender, "init")
msg.post(sender, "enable")
msg.post(constants.LEVEL_ID..":/common/player", "set_spawn_position", {spawn_point = spawn_point})
end
end
Player:
if message_id == hash("set_spawn_position") then
set_spawn_position(self, message.spawn_point)
end
local function set_spawn_position(self, spawn_point)
local sp_path = constants.LEVEL_ID..":/"..spawn_point
local sp_position = go.get_position(sp_path)
-- Setze Player Position
go.set_position(sp_position)
end