Map Toggling in Love2d (using STI And WindField)
Posted: Mon Dec 09, 2024 11:06 pm
Hello! i have made this account just 5 mins ago
well . . , i was trying to make map toggling in Love2d using sti and windfield for physical operations and colliders , etc . . .
then i have faced two problems
1) the first problem is that when the player goes to the next map the colliders of walls arent updated anymore like if i have two wall colliders and switched to the new map then those colliders are still out there in the next map
2) the player cant move when i switch to the new map the player is like freezed on the x axis and the player can move properly on y-axis but . . . when i added a debugging mode to check out if the player velocity is 0 or 1 to make sure that the problem is from those non-upgraded colliders , well . . that didnt happen because the velocity was normal (400 - 540) in my case so i dont really know how to fix those two problems , oh yeah i forgot to send the code , here you are :
Code: Select all
-- map width and height (used for conditions)
local map_width = game_map.width * game_map.tilewidth
local map_height = game_map.height * game_map.tileheight
if player.x > map_width then -- if player pass the screen x-axis position then . . .
-- Move to the next map
map_main = false -- the fist map (main)
map_right1 = true
current_map_index = 2
-- should load the map according to the current index is
game_map = maps[current_map_index]
-- reset player.x to 0 position
player.x = 0
-- walls is a table that contains every wall collider and [b]should remove them[/b]
for i , wall in ipairs(walls) do
-- also this code gives me an error and says that the error is from destroy method calling i dont really know if destroy method is
-- not in windfield anymore or it is updated
wall:destroy()
end
-- this code is for colliders updating but it doesnt work for some reason or it isnt complete code
walls = {}
if game_map.layers["colliders"] then
for i , obj in pairs(game_map.layers["colliders"].objects) do
local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
wall:setType("static")
table.insert(walls , wall)
end
end
-- Reset player's x position to the start of the new map
elseif player.x < 0 then -- elseif player.x is less than 0
map_main = true
map_right1 = false
local previous_map_width = game_map.width * game_map.tilewidth
player.x = previous_map_width -- Reset player to the end of the previous map
end
and also when i go to the previous map (by moving backwards from the main map) it gives me an error for cam movement limit condition
and i am sure that there is no missing variable
Thats all , thanks for reading , everyone