Fading

Get help using Construct 2

Post » Sun Oct 28, 2012 6:02 pm

I have an enemy with fade behavior and fade in/out both at 1 second. What I need to happen is the enemy starts out invisible, and when it is in the area of the player, it needs to fade into visibility. And then when it leaves the area of the player I want it to fade out. Not quite sure how to do this.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Sun Oct 28, 2012 10:59 pm

Use 2 fade behaviors for the same enemy. Fade1 fades in however long you want and "0" fade out (tell it to not destroy on fade out); Fade2 will have "0" fade in and however long you want it to fade out (tell it also to not destroy on fade out so that the same enemy is still moving around when it's invisible). Also make an empty sprite (no image, just a blank box) and link it to the enemy (look this up in a tutorial; the box will move with the sprite); make it as big as you want for however much space you want there to be between the player and the enemy when it appears.

For events, when the enemy is "On collision with" the blank sprite, "Start Fade1"; when the enemy is not "On Collision with" (inverted) the blank sprite, "Start Fade2".

If you are spawning enemies when they get in proximity with the player (which is probably what you should do to keep the game running smooth), then make sure you tell Fade2 to destroy on fade out (ignoring what I said above).
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Mon Oct 29, 2012 4:41 am

Thanks a lot! I don't have a computer available to use until tonorrow but reading through this it seems very logical. I was unaware you could have 2 fade behaviours so I was tryin to do it with 1 begavior that had a fade out and fade in time.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Mon Oct 29, 2012 2:01 pm

I just tried this out and I have one problem, since On Collision is a trigger it cannot be inverted.I have On Collision with the object it needs to fade into visibility, but once the player walks away it stays visible.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Mon Oct 29, 2012 2:16 pm

try inverting 'is overlapping' instead
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Oct 29, 2012 2:42 pm

Okay I'm starting to get somewhere, however if I use Is Not Overlapping, then it keeps repeating the fade out when not near the player. Whereas I need it to fade out and then stay invisible until it gets near the player again.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Mon Oct 29, 2012 4:38 pm

Oops, sorry about that. Damn, now I want to figure this out so I'm gonna have to do it.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Mon Oct 29, 2012 9:51 pm

I can get it to either fade out fine when not near but when it gets near it doesn't fade in, or get it to fade in fine when near but not fade out when the player moves away. Unfortunately I can't get both, still experimenting though!
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Tue Oct 30, 2012 2:19 am

I got it! The solution is to use the system "Trigger Once While True" Condition with the "Is Overlapping" event.

Use the arrow keys to move the player around (straight down is where the enemy is).

Here is the capx...
http://wayofthesax.com/tests/enemy%20proximity%20fading.capx

*pats self on back*ptbcomposer2012-10-30 02:20:11
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Tue Oct 30, 2012 3:30 am

One method, if you want it to fade in in relation to the player, is to set the opacity of the object depending on the distance between object and player.

So, set object opacity to 100-(distance(player.x,player.y, object.x,object.y*0.1)) for example.

This way its visibility will always be in relation to distance, instead of just fading all the way in or all the way out. Not sure if you want this, but just thought I'd give an idea :)
B
27
S
8
G
5
Posts: 429
Reputation: 6,902

Next

Return to How do I....?

Who is online

Users browsing this forum: MarkThomas, theosciandra and 18 guests