Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to Make a Day/Night Cycle
- shrubmaster
-
5 posts
How to Make a Day/Night Cycle
I'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
- ResExsention
-
1000+ posts
How to Make a Day/Night Cycle
I'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
Last edited by ResExsention (May 22, 2019 04:27:29)
- deck26
-
1000+ posts
How to Make a Day/Night Cycle
NEVER use the equals wirth the built-in timer as you're very unlikely to hit the exact value - use inequality like greater than or less than. For example, the timer may go from 6.99 seconds to 7.02 seconds between one check and the next so (apparently) never be equal to 7.I'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
Last edited by deck26 (May 22, 2019 08:28:34)
- ResExsention
-
1000+ posts
How to Make a Day/Night Cycle
NEVER use the equals wirth the built-in timer as you're very unlikely to hit the exact value - use inequality like greater than or less than. For example, the timer may go from 6.99 seconds to 7.02 seconds between one check and the next so (apparently) never be equal to 7.I'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
Lol. My logic when I wrote that code was that a timer would always hit every value. Didn't know it was that inaccurate.
- deck26
-
1000+ posts
How to Make a Day/Night Cycle
It's accurate, not inaccurate.NEVER use the equals wirth the built-in timer as you're very unlikely to hit the exact value - use inequality like greater than or less than. For example, the timer may go from 6.99 seconds to 7.02 seconds between one check and the next so (apparently) never be equal to 7.I'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
Lol. My logic when I wrote that code was that a timer would always hit every value. Didn't know it was that inaccurate.
Scratch will generally loop approx 30 times a second so roughly 0.033 seconds pass between one check of your if statement and the next. So the chances of you checking the time exactly on a whole second number are very slim.
- shrubmaster
-
5 posts
How to Make a Day/Night Cycle
I think I figured it out.
Last edited by shrubmaster (May 24, 2019 01:26:42)
- legendofv
-
1 post
How to Make a Day/Night Cycle
it didnt work for meI'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
- Feigh10
-
19 posts
How to Make a Day/Night Cycle
It's not necroposting.Don't Necropost.it didnt work for meI'm in the middle of making a real-time farming game set on local time, and I've got my backgrounds set up to change every 15 minutes. I was trying to set up a moon/sun that scrolls from the left of the screen to the right to simulate the sun/moon rise/set, and I'm trying to figure out if there's a better way to set up the movement rather than 96 if-statements or altering my backgrounds to include the moon/sun.
Again, you could use a timer, and go like:
- Itchy-Scratchy-show
-
1 post
How to Make a Day/Night Cycle
I actually have a Day/Night Cycle project to look at or use for reference or just download and re-time in your projects. https://scratch.mit.edu/projects/1118817116/
Last edited by Itchy-Scratchy-show (Today 03:47:59)
- Discussion Forums
- » Help with Scripts
-
» How to Make a Day/Night Cycle