Hi Aquila :)
As a reference for future questions. You can surround your source code with 3 punctuation marks ```
at the beginning and end. Makes it look much nicer :)
There are several things in your code that need to be fixed. Let me try one by one and I hope it makes sense.
The draw loop, your code:
draw = function()
screen.fillRect(0,0,screen.width,screen.height,"rgb(57,0,587)")
screen.drawMap("polonuovo", 0,0,2000,2000)
screen.clear
screen.drawSprite("alessandro", player.x-camera.x, player.y-camera.y 40, 40)
end
- screen.fillRect(...) will fill the whole screen with a blueish color. I guess that is the background.
- screen.drawMap(...) here you draw your map
- screen.clear() !!! This will clear the whole screen ... and your map will disappear!
- screen.drawSprite(...) and now you draw your player
The screen can be cleared and it's background color defined by using the screen.clear("color") command.
Also, the drawMap also needs to incorporate the camera shift to scroll along with it. The whole thing would now look like this:
draw = function()
screen.clear("rgb(57,0,587)")
screen.drawMap("polonuovo", 0-camera.x,0-camera.y,2000,2000)
screen.drawSprite("alessandro", player.x-camera.x, player.y-camera.y 40, 40)
end
Uff, running out of time, I continue later, sorry. Other things you forgot were that you actually have to call your initCamera and updateCamera function to make them do some work. You only defined them.
I attach a quick and dirty example for now... gotta run.
https://microstudio.io/i/TinkerSmith/_help/
// some values are changed to suit this example
init = function()
player = object
x = 0
y = 0
speed = 1
end
initCamera() // needs to be called once to initialize it
end
update = function()
if keyboard.UP then player.y += player.speed end
if keyboard.DOWN then player.y -= player.speed end
if keyboard.RIGHT then player.x += player.speed end
if keyboard.LEFT then player.x -= player.speed end
updateCamera() // call on each update
end
draw = function()
screen.clear("rgb(57,0,587)") // clears the screen and sets the background color
screen.drawMap("map", 0-camera.x,0-camera.y,480,320)
screen.drawSprite("icon", player.x-camera.x, player.y-camera.y, 30, 30)
end
//==================== function list =======================
initCamera = function()
camera = object
x = 0
y = 0
end
end
updateCamera = function()
camera.x = clamp(player.x, -200, 200)
camera.y = clamp(player.y, -156, 156)
end
clamp = function(value, lower_limit, upper_limit)
local val = max(value, lower_limit)
val = min(val, upper_limit)
return val
end