Log In  


Cart #42526 | 2017-07-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
14

I got a lot of comments about my smooth camera transitions in a recent WIP that I posted. I thought I'd just go ahead and share how I did it with a code sample cart. I'm posting the important function below, but feel free to look at the cart's code to see how it's implemented. I'm not a wizard, and I know it could probably be simplified somehow, so feel free to use and improve as you see fit. If you do improve it, let me know here so I can update the code for others to see!

function smooth_cam(spd)
 cam_x+=(flr(p.x/128)*128-cam_x)*spd
 cam_y+=(flr(p.y/128)*128-cam_y)*spd
 if (abs(cam_x-flr(p.x/128)*128)<0.5) cam_x=flr(p.x/128)*128
 if (abs(cam_y-flr(p.y/128)*128)<0.5) cam_y=flr(p.y/128)*128
 camera(cam_x,cam_y)
end

UPDATE: I fixed a minor bug. (I had smooth_cam(speed) running after map(0,0), when it should be running before. I also added the Z/X buttons to allow you to change the speed of the transition for this demo so you can see what different speeds look like.

14


Nice!


This type of thing is why i keep coming back to the BBS :) Thank you!!!



[Please log in to post a comment]