Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Adding zoom to my game
- Oisthebestletter
-
100+ posts
Adding zoom to my game
Hey! I wanted to add zoom to this game. I realized that this game is so complicated I should have done it from the start. Can someone provide a good algorithm for zoom without having to change the costumes to be bigger or smaller? I have tried:
((100) * (ZOOM))But that dosent work if you don't want them to have different sizes.
- NMario84
-
1000+ posts
Adding zoom to my game
The only way to achieve the “zoom” effect is to change the size of all the sprite assets to my knowledge.
What you “could” do is set a global ‘Zoom’ variable for every sprite, so you could change ONE variable to be able to change all sprites sizes at once.
What you “could” do is set a global ‘Zoom’ variable for every sprite, so you could change ONE variable to be able to change all sprites sizes at once.
- Oisthebestletter
-
100+ posts
Adding zoom to my game
(#2)Yes, but I said:
The only way to achieve the “zoom” effect is to change the size of all the sprite assets to my knowledge.
What you “could” do is set a global ‘Zoom’ variable for every sprite, so you could change ONE variable to be able to change all sprites sizes at once.
But that dosent work if you don't want them to have different sizes.
- cs4912647
-
20 posts
Adding zoom to my game
I am not expert at such maths, but assuming this is a dilation around the origin (things shrink relative to the origin) you must update both size and position. I think this is not quite mathematically accurate but good enough for a general purpose…
Hope this helps.
foreverAdd this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
go to x: ((x position)*((ZOOM)/(100))) y: ((y position)*((ZOOM)/(100)))
set size to ((size)*((ZOOM)/(100))) %
//a ZOOM of 100 means no change, lower values mean smaller, higher values mean larger
Hope this helps.
- Oisthebestletter
-
100+ posts
Adding zoom to my game
(#4)How would I scale pen?
I am not expert at such maths, but assuming this is a dilation around the origin (things shrink relative to the origin) you must update both size and position. I think this is not quite mathematically accurate but good enough for a general purpose…foreverAdd this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
go to x: ((x position)*((ZOOM)/(100))) y: ((y position)*((ZOOM)/(100)))
set size to ((size)*((ZOOM)/(100))) %
//a ZOOM of 100 means no change, lower values mean smaller, higher values mean larger
Hope this helps.

- cs4912647
-
20 posts
Adding zoom to my game
I forgot to mention this before, every time you update a position, pen width, or size, multiply it by(#4)How would I scale pen?
I am not expert at such maths, but assuming this is a dilation around the origin (things shrink relative to the origin) you must update both size and position. I think this is not quite mathematically accurate but good enough for a general purpose…foreverAdd this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
go to x: ((x position)*((ZOOM)/(100))) y: ((y position)*((ZOOM)/(100)))
set size to ((size)*((ZOOM)/(100))) %
//a ZOOM of 100 means no change, lower values mean smaller, higher values mean larger
Hope this helps.
((ZOOM) / (100))This should fix that issue, hopefully…
- Oisthebestletter
-
100+ posts
Adding zoom to my game
nevermind
Last edited by Oisthebestletter (Feb. 1, 2025 13:51:39)
- cs4912647
-
20 posts
Adding zoom to my game
Okay, perhaps you don't use the original script I gave you, and do this instead…(#6)The repositioning part is not working, and I need help with the scrolling background.I forgot to mention this before, every time you update a position, pen width, or size, multiply it by(#4)How would I scale pen?
snip((ZOOM) / (100))This should fix that issue, hopefully…
For every instance of the following blocks, where
(x::)is the unscaled value that you would use if ZOOM were 100 (a ZOOM of 100 means normal zoom, think of it like a percentage)
move (x::) stepsreplace the
go to x: (x::) y: (x::)
glide (1) secs to x: (x::) y: (x::)
change x by (x::)
set x to (x::)
change y by (x::)
set y to (x::)
change size by (x::)
set size to (x::)
change pen size by (x::)
set pen size to (x::)
(x::)with
((x::)*((ZOOM)/(100))To clarify,
(x::)is whatever script you were using before you implemented zoom. In other words, it doesn't use the variable ZOOM ever. Just putting this here in case you were confused…
Also, if you ever need to zoom in, you will likely have to use the exploit where you upsize a blank sprite or downsize a large sprite to override the position and size bounding
One last thing: if you ever used
<touching (sprite v) ?>blocks, they may not behave the same way because of off screen collision disabling. I don't know a simple solution for this yet, but hopefully you won't find this a problem…
Last edited by cs4912647 (Feb. 1, 2025 21:55:39)
- Discussion Forums
- » Help with Scripts
-
» Adding zoom to my game