Hello, I am a project in codeacademy (multi-scened games) and I am in a part “Separate files”.
I am confused trying to solve the second step.
In the first part, I had to break a code into separate files, because there are be different scenes in the project, and the corresponding files for each scene must be organised.
That’s why the first instruction was very logical:
“To include new files, in index.html ,add two <script>
elements BELOW the <script>
element that links to the Phaser CDN. One of the <script>
will have a src attribute of “StartScene.js” and the other a src attribute of “GameScene.js” (the names of the two new blank files”
The result looks like this:
<script src="StartScene.js">
</script>
<script src="GameScene.js"></script>
<script src="game.js"></script>
The second step is very confusing:
“Copy the entire code for the StartScene
class from game.js and paste the code into the StartScene.js file.
Remove the code for the StartScene
class from game.js.”
First of all, the instruction does not explain, what the purpose of this step is. Besides, why do I have to set one code inside of the other, when the whole idea of this section is to break the files into separate codes?
I have experimented with different combinations( like this: ). I always receive one and the same error: “Did you copy the StartScene class into the StartScene.js file?”, which does not make things clearer.
When I check the hint, it just says: “All the code for the StartScene class should ONLY be StartScene.js.”
I do not get it, because I have already written only THIS code, and nothing else.
Here is my code: (link: https://www.codecademy.com/courses/learn-phaser/lessons/complexity-in-phaser/exercises/separate-files?action=resume_content_item)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Bug Dodger</title>
<style>
canvas {
width: 450px;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.16.2/dist/phaser.min.js"></script>
<!-- Add your script elements below: -->
<script src="StartScene.js">
</script>
<script src="GameScene.js"></script>
<script src="game.js"></script>
</body>
</html>