Log In  

Hi i need some help with the camera i don`t know what i did wrong nut it seem like my camera dosen't follow my player

Any ideas ?

Thanks a lot

Charles,

function _init()
player = {}
x= 60
y = 60
player.x = 60
player.y = 60
cam_x =60
cam_y =60
player.s = 1
end

function _update()
if (btn(0)) then player.x=player.x-10 end
if (btn(1)) then player.x=player.x+10 end
if (btn(2)) then player.y=player.y-10 end
if (btn(3)) then player.y=player.y+10 end
end

function _draw()
map(cam_x,cam_y)
camera(cam_x,cam_y)
cls()
spr(player.s,player.x,player.y)
end

P#47501 2017-12-18 16:53 ( Edited 2017-12-19 22:31)

The camera coordinates, CAM_X and CAM_Y, never change. They're initialized to 60 in _INIT() but never updated to match PLAYER.X and PLAYER.Y.

EDIT: You also might want to take a look at _DRAW() and compare it to _DRAW() in this cart.

P#47506 2017-12-19 00:35 ( Edited 2017-12-19 06:08)

Also, in addition to what @tarek said, the camera location isn't the center of the screen, but where the top-left should be. So with the code you have, your character would be pinned to the top-left of the screen. If you're using an 8x8 sprite (1 sprite), then you'd want the camera to be at camera(player.x-60,player.y-60) instead.

P#47517 2017-12-19 17:31 ( Edited 2017-12-19 22:31)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 03:51:30 | 0.008s | Q:12