Log In  

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

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)
 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

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)


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]

Follow Lexaloffle:          
Generated 2023-01-30 10:42:16 | 0.013s | Q:14