Discuss Scratch

Oisthebestletter
Scratcher
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
Scratcher
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.
Oisthebestletter
Scratcher
100+ posts

Adding zoom to my game

NMario84 wrote:

(#2)
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.
Yes, but I said:

I wrote:

But that dosent work if you don't want them to have different sizes.
cs4912647
Scratcher
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…
forever
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
Add this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
Hope this helps.
Oisthebestletter
Scratcher
100+ posts

Adding zoom to my game

cs4912647 wrote:

(#4)
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…
forever
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
Add this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
Hope this helps.
How would I scale pen?
cs4912647
Scratcher
20 posts

Adding zoom to my game

Oisthebestletter wrote:

cs4912647 wrote:

(#4)
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…
forever
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
Add this script to every sprite and I think that's it, just a quick way to maintain normal zoom without affecting relative size
Hope this helps.
How would I scale pen?
I forgot to mention this before, every time you update a position, pen width, or size, multiply it by
((ZOOM) / (100))
This should fix that issue, hopefully…
Oisthebestletter
Scratcher
100+ posts

Adding zoom to my game

nevermind

Last edited by Oisthebestletter (Feb. 1, 2025 13:51:39)

Oisthebestletter
Scratcher
100+ posts

Adding zoom to my game

cs4912647 wrote:

(#6)

Oisthebestletter wrote:

cs4912647 wrote:

(#4)
snip
How would I scale pen?
I forgot to mention this before, every time you update a position, pen width, or size, multiply it by
((ZOOM) / (100))
This should fix that issue, hopefully…
The repositioning part is not working, and I need help with the scrolling background.
Oisthebestletter
Scratcher
100+ posts

Adding zoom to my game

bump
cs4912647
Scratcher
20 posts

Adding zoom to my game

Oisthebestletter wrote:

cs4912647 wrote:

(#6)

Oisthebestletter wrote:

cs4912647 wrote:

(#4)
snip
How would I scale pen?
I forgot to mention this before, every time you update a position, pen width, or size, multiply it by
((ZOOM) / (100))
This should fix that issue, hopefully…
The repositioning part is not working, and I need help with the scrolling background.
Okay, perhaps you don't use the original script I gave you, and do this instead…

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::) steps
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::)
replace the
(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)

Powered by DjangoBB