Log In  

Cart [#42526#] | Code | 2017-07-16 | License: CC4-BY-NC-SA | Embed
6

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.

P#42455 2017-07-13 22:22 ( Edited 2017-09-22 22:08)

:: sloum

Nice!

P#42473 2017-07-14 14:14 ( Edited 2017-07-14 18:14)

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

P#44458 2017-09-22 18:08 ( Edited 2017-09-22 22:08)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-07-15 17:57 | 0.042s | 4194k | Q:22