Log In  

Cart #25597 | 2016-07-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

I made this bit of code for creating a parallax effect for side-scrolling games. It uses three layers of infinitely repeating maps. I've set it up so that all the code is in a self-contained section that can be copied and pasted below your own code, with just an initialise, update and draw function needing to be called from the respective functions in your game.

More complete instructions can be found in the header of the code.

I hope somebody finds it useful!


P#25598 2016-07-20 04:33 ( Edited 2016-07-20 13:42)

This is awesome. Thanks for sharing, I totally think this will come in handy for me.

P#25602 2016-07-20 06:27 ( Edited 2016-07-20 10:27)

Nifty. Might be worth noting that since your star field is simple shapes, you can probably draw most of them using built-in methods like circfill() or rectfill() or even just pset() to set the color of pixels.

Not only can it then be really random, I'd think it would be faster to render than any sprite or map since it doesn't have to fetch that resource at all.

Check out my RGB shooter cart, it has a random pixel star background. Not much variance in color/size as your map version but should be enough in there to work with. However, I just took that star code from some other cart, so I don't claim the code behind it.

P#25611 2016-07-20 09:13 ( Edited 2016-07-20 13:13)

Ahh that's a great tip about not using sprites. To be honest I wanted to make a parallax effect that could be reused for lots of different games, not just space, so sprites need to be used for that. However for a space game, yeah definitely the methods you suggest are better.

P#25615 2016-07-20 09:42 ( Edited 2016-07-20 13:42)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-12-05 21:19:15 | 0.010s | Q:19