How to Make a Game with Day/Night Mode in Scratch | Tutorial

Alphabets Sounds Video

share us on:

In this lesson, we learned how to create a day and night cycle in Scratch, enhancing the visual appeal of our projects. We covered how to design a night effect using a dark rectangle, switch between day and night modes with keyboard inputs, and animate a dog sprite to sleep at night using costume changes and broadcasts. Additionally, we explored automating the cycle to transition every five seconds, making our projects more dynamic and engaging.

How to Make a Game with Day/Night Mode in Scratch

Hello everyone! Today, we’re going to learn how to add a cool day and night cycle to your Scratch projects. This can make your games, animations, or virtual pet simulators more interesting. Let’s dive in!

Creating the Night Effect

Imagine you have a project with a dog, and you want to show day and night. Here’s how you can do it:

First, choose a sprite and click on the paint option. Draw a big rectangle that covers the whole screen. Make it dark blue or black to look like night. This rectangle will be our “night cover.”

Next, go to the code tab. In the “Looks” category, find the block called “set color effect.” This block lets you change how things look. We will use the “ghost effect” to make the rectangle see-through. The higher the number, the more see-through it is. Set it to 50 for night mode.

Switching Between Day and Night

To switch back to day, use another ghost effect block and set it to 100. This makes the night cover invisible, showing the day. We can use keyboard keys to switch between day and night. Go to the “Events” category and drag out a “when space key pressed” block. This will switch to night mode when you press the space key. Use another block to switch to day mode when you press the A key.

When you click the green flag, the night cover will be invisible, showing it’s day. Make sure the night cover is in front of other sprites so it covers them properly.

Making the Dog Sleep

Let’s make the dog do something fun when it turns to night, like going to sleep. Click on the dog sprite and create a new costume showing it with closed eyes. You can duplicate the current costume and change the eyes to look closed.

Go back to the code tab and use the “switch costume” block to change between the awake and sleeping costumes. To make this happen when switching between day and night, we’ll use broadcasts.

Using Broadcasts

Broadcasts are like invisible messages that tell sprites what to do. In the night cover sprite, send a broadcast when switching to day and another when switching to night. When the space key is pressed, broadcast “Switch to Night.” When the A key is pressed, broadcast “Switch to Day.”

In the dog sprite, use the “when I receive” block to change to the regular costume when it gets “Switch to Day” and to the sleeping costume when it gets “Switch to Night.”

Testing and Automating the Cycle

Now, let’s test it! Press the A key to switch to day mode and the space key to switch to night mode. The dog should close its eyes at night. You can even add a thought bubble with “Z’s” to show it’s sleeping.

If you want the day and night to change automatically, you can do that too. In the night cover sprite, after clicking the green flag, create a loop that waits a few seconds, like five, before switching to night. Duplicate this to switch back to day after another five seconds.

Now, your project will switch between day and night every five seconds. To start with the dog awake, broadcast “Switch to Day” when the green flag is clicked.

Conclusion

That’s it for today’s tutorial! I hope you have fun creating projects with day and night cycles. Thank you for following along, and happy scratching!

  1. What was the most surprising or interesting aspect of implementing a day/night cycle in Scratch that you learned from the article?
  2. How do you think adding a day/night cycle can enhance the user experience in a Scratch project?
  3. Reflect on the process of creating the night effect. What challenges might you encounter, and how would you address them?
  4. Consider the use of broadcasts in the tutorial. How do you see this feature being useful in other types of Scratch projects?
  5. What creative ideas do you have for using the day/night cycle in a project other than the example provided in the article?
  6. How does automating the day/night cycle change the dynamics of the project, and what potential improvements could you make?
  7. In what ways can you personalize the dog sprite’s behavior during the day/night cycle to make it more engaging?
  8. What additional features or elements could you add to the project to make the day/night cycle more realistic or interactive?
  1. Create Your Own Night Cover

    Start by designing your own night cover! Use the paint tool in Scratch to draw a large rectangle that covers the entire screen. Choose a dark color like blue or black. Experiment with different shades to see which one looks best for your night scene.

  2. Code the Day/Night Switch

    Use Scratch blocks to switch between day and night. Try using the “when key pressed” blocks to change the ghost effect of your night cover. See if you can make it switch smoothly between day and night by adjusting the transparency levels.

  3. Animate Your Sprite

    Get creative with your sprite! Design a new costume for your sprite that shows it sleeping. Use the “switch costume” block to change your sprite’s appearance when it turns to night. Can you add any other animations to make it more fun?

  4. Experiment with Broadcasts

    Learn how to use broadcasts to communicate between sprites. Create broadcasts for switching to day and night, and see how they can trigger different actions in your project. Try adding more broadcasts for other events, like sunrise or sunset.

  5. Automate the Day/Night Cycle

    Challenge yourself by automating the day and night cycle. Use loops and timing blocks to make the cycle change automatically. Experiment with different time intervals to see how it affects the flow of your project.

Sure! Here’s a sanitized version of the transcript, removing any informal language and maintaining a clear instructional tone:

Hello everyone, this is Zia. Today, I will demonstrate how to implement day and night cycles in any Scratch project. This feature can be useful for games, animations, or virtual pet simulators. Let’s get started.

For this example, let’s assume I have a project featuring a dog, and I want to incorporate day and night modes. Here is one method to achieve this. First, select a sprite and click on the paint option. I will create a dark blue or black rectangle to cover the entire screen, simulating a night effect.

Using the rectangle tool, I will set the color to a dark shade of blue and extend the rectangle to cover the whole screen. Currently, this rectangle is completely opaque. To adjust its transparency, I will click on the code tab. In the looks category, I will find the block labeled “set color effect.” This block offers various effects, including a ghost effect. By selecting the ghost effect, I can modify the transparency level. Higher values increase transparency, with 100 being completely transparent and 0 being fully opaque. I will set the transparency to 50 for the night mode.

To switch back to day mode, I will use another ghost effect block and set it to 100, making the night cover completely transparent. This allows us to toggle between day and night using keyboard inputs. I will go to the events category and drag out a “when space key pressed” block to switch to night mode when the space key is pressed. Additionally, I will set it to switch to day mode when the A key is pressed.

Now, when the green flag is clicked, the night cover will be completely transparent, indicating day mode. I will also ensure it is positioned in front of any sprite so that the night cover effectively overlays them.

Next, let’s make the dog sprite perform an action when switching to night mode, such as appearing to sleep. To do this, I will click on the dog sprite and create a new costume that depicts it sleeping. I will duplicate the existing costume and modify the eyes to appear closed. After adjusting the eyes, I will return to the code tab and use the “switch costume” block to alternate between the two costumes.

To trigger this costume change when switching between day and night, I will create broadcasts. In the night cover sprite, I will send a broadcast when switching to day and another when switching to night. A broadcast is an invisible message that one sprite can send, prompting other sprites to respond accordingly. When the space key is pressed, I will broadcast a message called “Switch to Night,” and when the A key is pressed, I will broadcast “Switch to Day.”

In the dog sprite, I will use the “when I receive” block to switch to the regular costume upon receiving “Switch to Day” and to the sleeping costume upon receiving “Switch to Night.”

Now, let’s test this functionality. Pressing the A key will switch to day mode, and pressing the space key will switch to night mode, causing the dog to close its eyes. I can also have the dog display a thought bubble, such as “Z’s,” when it switches to night mode.

If you wish to automate the transition between day and night every few seconds, I will demonstrate how to do that. In the night cover sprite, after the green flag is clicked, I will create a loop that waits a specified amount of time, such as five seconds, before switching to night mode. I will duplicate this code to switch back to day mode after another five seconds.

Now, the project will alternate between night and day every five seconds. Lastly, to ensure the dog starts with its eyes open, I will broadcast “Switch to Day” when the green flag is clicked.

That concludes today’s tutorial. I look forward to seeing the projects you create with day and night cycles. Thank you for watching, and happy scratching!

This version maintains the instructional content while removing informal language and ensuring clarity.

ScratchA visual programming language that allows you to create your own interactive stories, games, and animations. – In Scratch, you can drag and drop blocks to create a fun game.

SpriteA character or object in a Scratch project that you can program to move and interact. – I added a cat sprite to my Scratch project and made it dance.

NightA time when it is dark, often used in coding to change the appearance of a game or animation. – In my game, the background changes to a starry sky at night.

DayA time when it is light, often used in coding to set a bright and cheerful scene. – During the day, the game shows a sunny park with kids playing.

CodeA set of instructions written in a programming language to make a computer do something. – I wrote code to make the sprite jump when I press the space bar.

CostumeA different appearance or outfit for a sprite in Scratch, which can be used to create animations. – I changed the sprite’s costume to make it look like it was running.

BroadcastA message sent in Scratch to trigger actions in other sprites or scripts. – When the game starts, it broadcasts a message to all sprites to begin moving.

EffectA change applied to a sprite or background to make it look different, like changing colors or adding a blur. – I added a ghost effect to the sprite to make it look spooky.

KeyA button on the keyboard that can be used to control actions in a program. – Pressing the arrow key makes the sprite move forward in the game.

CycleA sequence that repeats over and over in a program, often used to create loops. – The sprite goes through a cycle of costumes to make it look like it’s walking.

All Video Lessons

Login your account

Please login your account to get started.

Don't have an account?

Register your account

Please sign up your account to get started.

Already have an account?