# Screen Fade Bug

**URL:** <https://forum.playcanvas.com/t/screen-fade-bug/38290>\
**Category:** Help & Support\
**Created:** [November 18, 2024, 6:52pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290 "2024-11-18T18:52:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 18, 2024, 6:52pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/1 "2024-11-18T18:52:07Z")

</div>

I am trying to make a screen fade between scenes for my current project(I know I posted about 2 other projects recently, but I am only helping someone with one, and the other will be my next project), and I tried to do a screen fade that happens between scenes, the fade works in Sector 1, but Sector 3 is unplayable because the entity that has fades out is not fading, what am I doing wrong and is there an easier way to do a screen fade?

Project link to Sector 3: [PlayCanvas | HTML5 Game Engine](https://playcanvas.com/editor/scene/2047897)

Link to script with the fade in/out code: [PlayCanvas | HTML5 Game Engine](https://playcanvas.com/editor/code/1242480?tabs=191323224&focused=191323224)

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 18, 2024, 8:25pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/2 "2024-11-18T20:25:09Z")

</div>

I’m not sure it is any easier but here is an example of using html element overlay to fade in and out. [https://playcanvas.com/project/1202866/overview/scene-change-with-asset-preload](https://playcanvas.com/project/1202866/overview/scene-change-with-asset-preload). You can use the 1 to 9 keys to change scenes.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 2:26pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/3 "2024-11-19T14:26:34Z")

</div>

the problem with this one is unloading all assets after the transition starts, which I tested with my previous project, sometimes the global variable may reset if there are no entities with those scripts in the new scene

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 2:44pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/4 "2024-11-19T14:44:37Z")

</div>

The scene\_transition,js files contains just the fading in/out code and could in theory be integrated into your scene switching code. Or can just be used as example code as a starting point. As you say that project’s focus was about loading/unloading assets so you don’t need those bits.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 2:59pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/5 "2024-11-19T14:59:00Z")

</div>

ok, cool, but I never used these types of scripting before(I never used any script that is labeled as:  
`class "Name Here" extends PC.Event_Handler`).

How do I trigger the transition?

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 3:25pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/6 "2024-11-19T15:25:27Z")

</div>

It’s going be a bit of a learning curve to use the code in the project in a plug and play way. As you spotted it’s not using the usual script format for scripts that are attached to entities. I set this project up so that the SceneManager and SceneTransition scripts are not attached to each scene, but instead are created just once at app startup and then they are available for the whole lifetime of the app. But the scene-transition.js script is self contained and self explanatory if you want to try and convert it to the usual script format you know and attach it to a scene.  
To answer your question though. If you want to create a new instance of the SceneTransition class and start the transition you would

```javascript
const sceneTransition = new SceneTransition(this.app);
await sceneTransition.start();

```

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 3:30pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/7 "2024-11-19T15:30:34Z")

</div>

where would I put it?

during the instance where the scene transition starts?

or during the instance where the scene transition trigger activates?

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 3:34pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/8 "2024-11-19T15:34:43Z")

</div>

I’d need to take a look at your code. I’ll see if I have time in a few hours.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 3:40pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/9 "2024-11-19T15:40:48Z")

</div>

if you didn’t see it above, here: [PlayCanvas | HTML5 Game Engine](https://playcanvas.com/editor/code/1242480?tabs=191323224&focused=191323224)

while looking through Scene Manager, it seems like it is on a continuous repeat, so I think it might be best if it was where the scene change trigger is active, but the trigger is not happening.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 4:28pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/10 "2024-11-19T16:28:34Z")

</div>

also, do you know how to detect the current scene, it is necessary for the saving process. When the game saves, it saves the X and Y positions of the saving object(not the player’s x and y, that may look weird every time you respawn) \* 30(because, for every frame you move, Qiste moves 1/30 of a full unit(unless you go diagonally where it’s 1/30 in both directions your moving in)) put into Hexadecimal, the(main and key) items you collected in Bianary(to show what items you have easier), which optional items you collected in Bianary(as there are multiple of each them and I need a way to keep track of those individually) what bosses are defeated in Binary\*, and finally the scene name that shows which scene you last saved in(I don’t know how I will save the scene name but I think it will be Hex codes of the letters, grouped together(and separated when decoding)

\*(there is one boss that doesn’t count towards the defeated bosses, because you have to fight another boss(A scavenger) right after it and you have to beat the scavenger without leaving the scene to prevent you from taking the strong weapon(that the first boss gave you) away, you lose the item after killing the scavenger in that boss fight, because it is only there to kill the scavenger, and you get the boss killed point for both the Robot & scavenger(Which are the same bit)once the scavenger is dead). there was a lot of info here which is why I added the asterisk footnote.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 4:33pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/11 "2024-11-19T16:33:43Z")

</div>

and yes, I do know how to save projects here.

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 4:37pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/12 "2024-11-19T16:37:32Z")

</div>

You should start a new topic for that.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 4:44pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/13 "2024-11-19T16:44:31Z")

</div>

the problem is, I checked Google for PlayCanvas forum, PlayCanvas API, and PlayCanvas developer pages for something that can help me find the Scene name, but nothing succeeded in helping the questioner do it, so I cannot find out how to do it(I think I got a workaround, but the problem comes with the default scene name, IDK what to make it as this will have 2 starting points(I should probably set it when you select which chapter to play)

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 4:52pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/14 "2024-11-19T16:52:59Z")

</div>

When you change scenes you pass the name of the scene. Just store that name somewhere.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 4:57pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/15 "2024-11-19T16:57:31Z")

</div>

that was my workaround, but when you start a new game, the variable is preset, so once I have the transition working, I will start making the title screen work.

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 5:03pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/16 "2024-11-19T17:03:22Z")

</div>

In the start scene before you have changed to another scene you can default the current scene name to the start scene name , because you know the start scene name. Is there anything else you are missing related to scene name? If so it’s better to ask a new question and not mix it up in this thread about fading.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 5:05pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/17 "2024-11-19T17:05:35Z")

</div>

no, thx

but are you able to find where to put the fade transition trigger in the scene change script?

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 5:06pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/18 "2024-11-19T17:06:58Z")

</div>

I’ll take a look this evening. I may fork your project if necessary to try things out.

---

<div class="post-metadata">

**Author:** ![Linkplayer](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/linkplayer/32/29263_2.png) [@Linkplayer](https://forum.playcanvas.com/u/Linkplayer)\
**Post date:** [November 19, 2024, 5:10pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/19 "2024-11-19T17:10:55Z")

</div>

that’s fine

---

<div class="post-metadata">

**Author:** ![Kulodo133](https://forum.playcanvas.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kulodo133](https://forum.playcanvas.com/u/Kulodo133)\
**Post date:** [November 19, 2024, 6:23pm UTC](https://forum.playcanvas.com/t/screen-fade-bug/38290/20 "2024-11-19T18:23:48Z")

</div>

I forked your project here [https://playcanvas.com/project/1277142/overview/fork-breached](https://playcanvas.com/project/1277142/overview/fork-breached)

- a made sector 1 transition to sector 3 and sector 3 transition to sector 1. I’ll leave it to you to fix up the other scenes.
- I removed various attached to entity ‘change scene’ script that hadn’t set the ‘scene’ attribute.
- I name the entity with the ‘change scene’ script SCENE CHANGER so you can find it.
- I attached the playcanvas tween script needed by my script for the fading.
- I modified your ‘change scene’ script to call create a new instance of my script and call the start and complete methods of that script to do the fadeout and fadein.

[Next page](https://forum.playcanvas.com/t/screen-fade-bug/38290.md?page=2)
