Possible to cut off a gradient light?

Discussion and feedback on Construct 2

Post » Thu Aug 13, 2015 4:17 am

I'm exploring lighting systems in construct 2, which are a little less than I would hope for. But right now I've got a fog layer with black square as the darkness, and a destination out gradient acting as the gun light. The problem is it shines through everything, So I want to know if there is a way to block this light or another method of doing this entirely. Thanks!

Image
B
72
S
24
G
11
Posts: 452
Reputation: 12,387

Post » Thu Aug 13, 2015 7:13 am

You could try ray casting but it adds quite a bit of overhead.
B
51
S
16
G
9
Posts: 1,098
Reputation: 11,252

Post » Thu Aug 13, 2015 3:45 pm

You can absolutely block it. This example isn't exactly what you're trying to do, but it has the principles that will show you how.

Lantern Example

EDIT:

Alright, I modified it quickly to do a true flashlight. I made it to work with layers that aren't necessarily 100% dark (they're translucent) so it can fit more applications.

Flashlight Example
Just so you know, it's important that the flashlight sprite is at the bottom of the layer (under the shadow objects) for this to work.
And here's it running in a browser so you can preview the effect: Flashlight Demo (arrows keys to move, mouse to aim the light)
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Thu Aug 13, 2015 6:20 pm

@C-7 Awesome, thanks so much! I didn't know shadowlight would work with destination out systems.
B
72
S
24
G
11
Posts: 452
Reputation: 12,387

Post » Thu Aug 13, 2015 7:03 pm

@ReflextionsDev

C-7's example is awesome - but it might be more advanced than what you need (and more cpu costly than you want). (or maybe it is just my very slow work computer, lol)

You may be able to do it the way you started above, but just isolate the light and fog area of the current room on a separate layer. Then that wont affect fog outside the current room (on a different layer)...

Nice thing about C2 is you can have LOTS of layers!
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Thu Aug 13, 2015 7:22 pm

AllanR wrote:@ReflextionsDev

C-7's example is awesome - but it might be more advanced than what you need (and more cpu costly than you want). (or maybe it is just my very slow work computer, lol)

You may be able to do it the way you started above, but just isolate the light and fog area of the current room on a separate layer. Then that wont affect fog outside the current room (on a different layer)...

Nice thing about C2 is you can have LOTS of layers!


I kinda had a system like that but it would be clunky when you move from each room, one goes dark and the other whole room appears. Though, now I'm getting a weird glitch where if you shine up at the roof, it will go through like halfway in some places.

https://dl.dropboxusercontent.com/u/441 ... index.html

Image
B
72
S
24
G
11
Posts: 452
Reputation: 12,387

Post » Thu Aug 13, 2015 7:49 pm

That just looks like you have something set up wrong (if it works everywhere else, it should work anywhere). Put an event in that sets your flashlight object to the back of the layer just to make sure it's never anywhere else no matter what you do in C2. I mean, I can get light show "show through" further on up if the light object overlaps the shadow boundary, but that shouldn't matter in your game's case.

If you're looking for an alternative, I wouldn't jump things around layers--that sounds like it'll come back to haunt you later. I suppose you could always place a black tiled background on the floor above (and below depending) that stays locked there until you switch levels to hide anything.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Thu Aug 13, 2015 11:22 pm

C-7 wrote:That just looks like you have something set up wrong (if it works everywhere else, it should work anywhere). Put an event in that sets your flashlight object to the back of the layer just to make sure it's never anywhere else no matter what you do in C2. I mean, I can get light show "show through" further on up if the light object overlaps the shadow boundary, but that shouldn't matter in your game's case.

If you're looking for an alternative, I wouldn't jump things around layers--that sounds like it'll come back to haunt you later. I suppose you could always place a black tiled background on the floor above (and below depending) that stays locked there until you switch levels to hide anything.


It's definitely staying behind them, I'm using other invisible objects to control lighting. Maybe it is overlapping the shadow boundary is there a way to control that? Image
B
72
S
24
G
11
Posts: 452
Reputation: 12,387

Post » Fri Aug 14, 2015 1:03 am

It only overlaps if your light source gets right up on the wall and crosses into it (your light source should be right at or near your player). I'm not sure how to fix your specific problem--I can't make it happen in my own tests. I'd definitely be willing to glance through your capx if you're willing to PM it to me, but it's tough to tell from here.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests