Terraria

0 favourites
  • Hello,

    I have been trying to make a game that has some similar things as Terraria. I have the swinging, inventory, crafting, day/night, and many other things. The one thing I am stumped on is the lighting. The lighting should be similar: The light spills from a light source. It loses a little brightness over air, and much more over blocks. The tile size would be 8x8. If I used sprites, there could be thousands and that would take a lot of processing. A tilemap would not be as versatile, but would definately be better performance. I think the secret might lie in arrays. The only way to do it with sprites would be to somehow only process the ones that are on the screen or withing, say, 100 pixels.

    I found this thread (unfortunately all of the links are down):

    https://www.construct.net/en/forum/construct-classic/help-support-using-construct-38/tilebased-light-kinda-40297

    Here is what the light is like:

    Any help with this would be appreciated.

    Thank you, Give me a Pixel

    Tagged:

  • What about the shadowlight? It's not too similar but provides lighting effects.

    For a similar effect I think a canvas could work pretty well. Adding brightness tile by tile based in distance to light sources and removing brightness if the tile isn't empty.

  • The built in shadow light? That really wouldn't work for what I'm thinking. It doesn't necessarily have to be in tiles, but I thought that would be easiest. Maybe Scirra or even a third-party developer could create something like 'spill lighting.'

  • Well the simple option would be to use the inbuilt shadow lights.

    As for a more complicated solution:

    The first thing that comes to mind is for each tile find every nearby light, calculate the distance then pick the shortest distance.

    If your game has less than 10 lights then this is fine, the cost is minimal. If your going to allow the users to place lights... Well you could have 10 thousand plus it's going to run slowly. So how to speed it up?

    First optimisation is to use the Manhattan distance instead of Pythagoras. Much faster, but it's visually quite different ( diamonds not circles ). This normally suits tile/voxel based games though.

    Second trick is spatial partitioning. If the maximum range of a light is 8 tiles, then split the world up into 8x8 chunks. When you need to look for nearby lights you only need to check the current chunk and it's immediate neighbours. This makes for a worst case of 575 lights to check, instead of the whole world, and finding the lights is pretty simple.

    If you want to simulate sunlight then a good trick is treat every tile that has no obstruction above it as a light source. This gives you an approximation of indirect illumination for sunlight, which is nice.

    You should only be updating these light values if the world changes, not every tick. If you use spatial partitioning then it's easy enough to update the 9 chunks centered around the changed tile which could be affected. For sunlight it's a little more fiddly unfortunately...

    There is another trick you can do which improves the quality of your lighting, but I'm not sure how you'd manage it in Construct. Basically the trick is to calculate light for the corners of tiles instead, then interpolate it across the tile to give you smooth lighting changes. If you make solids completely dark then this will also give you an Ambient Occlusion effect.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maybe Scirra or even a third-party developer could create something like 'spill lighting.'

    In practise this style of lighting is VERY specific to this kind of game, and generally quite closely linked to how your game works. The only reason why I know so much about it is because I've been doing research into voxel lighting techniques for my own game project.

  • Nepeo with the wisdom. I´m pretty sure a good portion of what you said applies to terraria (manhattan distance, chunking and even the way sunlight works)

  • Whoa, that sounds complex. If you have a .c3p file you could share that would definitely clarify it. If not than I could try to break this down and create it. . .

  • Well most of what I know is theory, I'm part way through implementing it for Wings but that is all 3D and written in JavaScript, so it's not apples to apples really. I basically just have the Ambient Occlusion effect at the moment.

    I did make the procedural terrain generation example which covers some of these concepts. It stores data for chunks by packing tile data into a JSON object, converting that to a string then placing it in a Dictionary. The Dictionary being keyed with the location of the chunk.

    There's plenty of room for optimising that project and tweaking other stuff, it was mostly meant to show off the ideas.

    If you want I can give you some psuedo code for it. But some experience reading code would probably be required? Not sure what your background is, quite a few construct users would struggle with psuedo code.

  • Actually I've never heard of pseudo code before. I really have no clue how to do what your saying.

    Just an idea: Would arrays work? I've never used them before though, but I've heard they're pretty cool.

  • I'm sure if I got the code, I don't know what it looks like or is, but I might be able to make something similar to it if I saw it. If it's really complex, I don't know if you would convert it into constuct code or not?

  • Ah so psuedo code is a term used by programmers. It's demonstrating roughly how an algorithm works using a fake programming language which is easy to understand. But unless you know a written programming language your unlikely to understand it unfortunately.

    Yes you would want arrays for this, one per "chunk" to hold a list of lights in that chunk. Then I'd use a separate dictionary which is used for finding the array for each chunk.

    It probably wouldn't be that quick for me to implement something like this unfortunately, so I can't really send you an example made it Construct right now.

  • Hmmm. I'm not sure what to do. I probably would not understand the psuedo code, but you could share it if you would like. Let me explain what a 'spill light' would do in case anybody wants to make it.

    It acts just like the regular shadow caster in that there are lights and behaviors for objects to block the light. It could be smooth or for tiles or an option for either. You would probably have to put it on a layer that was black, not transparent, and forced own texture. The light would deteriorate on it's own over distance without hitting an object. If it did hit an object, it would lose much more light. You could set the light's 'intensity' meaning that it would be brighter and reach farther. You could also set the tolerance on the behaviors for the objects that block the light to see how much light is let through. At 0% tolerance, it would be just like the built in shadow caster, at 50% half the light is let through and if the light hit another blocker object with %50, it would light that block up at %50 and let no light pass through. At 100% it would be like the block was not there.

    Hopefully somebody would create this. I would if I knew how but I don't. . .

    Thanks.

  • R0J0hound would you be interested in this? Or do you only make addons for C2?

  • Tokinsom

    Do you still have any of the links from this thread? I always get error 404.

    construct.net/en/forum/construct-classic/help-support-using-construct-38/tilebased-light-kinda-40297

  • here is a sample I made for someone months ago - it was specifically for how to make a mask object on the mask layer move with an object on a different layer with different parallax settings... (which is what is going on in event 13)

    I updated it a bit to allow for colored lights...

    there is a family called LightSources, and at the beginning of the layout, each instance of the family gets a glow object created for it, set to the appropriate settings for the object.

    This doesn't localize the light the way Terraria appears to, and it has nothing to do with tile sets, but hopefully it might give you some ideas! :)

    https://www.rieperts.com/games/forum/ColorLightMask.c3p

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)