Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Move and zoom camera to keep sprites on screen
- AndreiFren64
- Scratcher
100+ posts
Move and zoom camera to keep sprites on screen
In this game, I have a custom camera system that works quite well for keeping focus on the player, however as I intend to make it a fighting game, I need to keep multiple sprites on screen at any given time. How would I make it so that it places the camera at a point where any sprites I want to be visible are visible, and zoom it accordingly?
Examples of how I want it to act:
But preferrably, I'd like it to work with any number of sprites.
Examples of how I want it to act:
But preferrably, I'd like it to work with any number of sprites.
when I receive [attention on my projects v]
set [dreaming v] to <true>
broadcast [wake up v]
- crumbthehog
- Scratcher
92 posts
Move and zoom camera to keep sprites on screen
this game, I have a custom camera system that works quite well for keeping focus on the player, however as I intend to make it a fighting game, I need to keep multiple sprites on screen at any given time. How would I make it so that it places the camera at a point where any sprites I want to be visible are visible, and zoom it accordingly?your link isn't working, but if its a standerd scrolling engine, you are likely setting the cam x/y In
Examples of how I want it to act:
But preferrably, I'd like it to work with any number of sprites.
to the player x/y. you will need to set it the player x/y - the enemy x/y this will get the cam. in the middle of the two.
zooming it will take some more math, and will require some translating. it will also cause some scrolling issues if not done right.
Last edited by crumbthehog (Oct. 18, 2022 02:19:30)
-Crumb-
- AndreiFren64
- Scratcher
100+ posts
Move and zoom camera to keep sprites on screen
Oh, thank you, I thought I'd shared it. I'll share it now. your link isn't working, but if its a standerd scrolling engine, you are likely setting the cam x/y
to the player x/y. you will need to set it the player x/y - the enemy x/y this will get the cam. in the middle of the two.
zooming it will take some more math, and will require some translating. it will also cause some scrolling issues if not done right.
Last edited by AndreiFren64 (Oct. 18, 2022 08:36:24)
when I receive [attention on my projects v]
set [dreaming v] to <true>
broadcast [wake up v]
- crumbthehog
- Scratcher
92 posts
Move and zoom camera to keep sprites on screen
I looked at it. I tried to add the scrolling, but you have some strange hit-box thing going on. I could add it if you are ok with a bit of a code re-right.Oh, thank you, I thought I'd shared it. I'll share it now. your link isn't working, but if its a standerd scrolling engine, you are likely setting the cam x/y
to the player x/y. you will need to set it the player x/y - the enemy x/y this will get the cam. in the middle of the two.
zooming it will take some more math, and will require some translating. it will also cause some scrolling issues if not done right.
-Crumb-
- griefercube
- Scratcher
500+ posts
Move and zoom camera to keep sprites on screen
I remember seeing something like this before, but the theory is something like this:
record both sprites x and y position
Find their size (rectangular hitbox)
Use math to find the centre of both sprites (assuming it’s (x1+x2)/2)
then set zoom to the size/2+x1+x2 (or something like that)
yeah
record both sprites x and y position
Find their size (rectangular hitbox)
Use math to find the centre of both sprites (assuming it’s (x1+x2)/2)
then set zoom to the size/2+x1+x2 (or something like that)
yeah
sometimes, you just have to change a way of thinking to solve a problem. -griefercube
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
Last edited by griefercube (32th Undecimber, XXXX)
https://turbowarp.org/563693837/editor (something i did a while back don’t worry it’s for the banner)
list of working bbcodes:
[color=]
[scratchblocks]
[url=]
[img]
[center]
[code]
[code=]
[list]
[quote]
[b]
[i]
[u]
[s]
[big]
[small]
[p]
[wiki]
[google]
- TheFinalAndOnlyStuge
- Scratcher
1 post
Move and zoom camera to keep sprites on screen
Im having the exact same problem! i cant figure out how to make 2 characters stay on the same screen
- AndreiFren64
- Scratcher
100+ posts
Move and zoom camera to keep sprites on screen
I never finished this project but your best bet will probably be finding the point in between the two characters and then setting the zoom to be something divided by the distance between them Im having the exact same problem! i cant figure out how to make 2 characters stay on the same screen
im not a genius though idk
when I receive [attention on my projects v]
set [dreaming v] to <true>
broadcast [wake up v]
- Discussion Forums
- » Help with Scripts
- » Move and zoom camera to keep sprites on screen