Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Scrolling with clones
- DropKic
-
Scratcher
1 post
Scrolling with clones
How do I make clones do scrolling? I need this desperately for a project I am making. I have the scrolling part down, but I need the enemies to scroll with me.
- Siuozl_Labs
-
Scratcher
8 posts
Scrolling with clones
you want to use scripts that contain, first of all, “FOR THIS SPRITE ONLY” VARs.
This makes the data INDIVIDUAL to every clone.
Use:
To make different entities, do this:
Hope this helped!
This makes the data INDIVIDUAL to every clone.
Use:
when I start as a cloneto make a script running privately for every clone.
To make different entities, do this:
when I start as a cloneMake sure you use a script for cloning:
if <(id) = [1]> then
DO THIS…
DO THAT…
end
if <(id) = [2]> then
DO THIS OTHER THING…
DO THAT OTHER THING…
end
when something happens—
set [id v] to (1)
repeat (how many clones)
create clone of [myself v]
change [id v] by (1)
end
Hope this helped!
Last edited by Siuozl_Labs (May 10, 2023 01:17:40)
- Spentine
-
Scratcher
1000+ posts
Scrolling with clones
In order to create scrolling, you must have a camera position as a reference frame. I'll call the camera's position cam x and cam y. For each clone, to get it to move to the correct position, this formula can be used:
global position - cam position
Converting the vectors to normal Scratch variables will result in:
Just a note, position x and position y are “for this sprite only” variables and cam x and cam y are global variables.
This script will be created:
To move a clone, you simply modify its position variable. Try not to use the
block, but instead, you may consider using this:
It will become a bit more difficult to program if you use the <touching ()?> block frequently.
global position - cam position
Converting the vectors to normal Scratch variables will result in:
go to x: ((position x) - (cam x)) y: ((position y) - (cam y))
Just a note, position x and position y are “for this sprite only” variables and cam x and cam y are global variables.
This script will be created:
when I start as a clone
forever
go to x: ((position x) - (cam x)) y: ((position y) - (cam y))
end
To move a clone, you simply modify its position variable. Try not to use the
move () steps
block, but instead, you may consider using this:
define move (magnitude)
change [position x v] by ((magnitude) * ([sin v] of (direction)))
change [position y v] by ((magnitude) * ([cos v] of (direction)))
It will become a bit more difficult to program if you use the <touching ()?> block frequently.
- Siuozl_Labs
-
Scratcher
8 posts
Scrolling with clones
Maybe with a combination of those two it can help?
@Spentine, thx for completing.
If you need anymore help, comment on @ProSiuozl’s profile, my main acc.
@Spentine, thx for completing.
If you need anymore help, comment on @ProSiuozl’s profile, my main acc.
- bruno146
-
Scratcher
25 posts
Scrolling with clones
First set the start and end positions using variables (“For this sprite only”)
(start x)
(end x)
when I start as a clone
forever
go to x: (start x) y: (whatever you want)
repeat until <(x position) = (end x)>
move (10) steps
end
delete this clone
end
Last edited by bruno146 (May 11, 2023 10:29:04)
- bruno146
-
Scratcher
25 posts
Scrolling with clones
The previous 2 replies before mine might be correct, but I have never tried them. This is the way I make clones scroll and I think its a bit easier
- bruno146
-
Scratcher
25 posts
Scrolling with clones
First set the start and end positions using variables (“For this sprite only”)(start x)
(end x)when I start as a clone
forever
go to x: (start x) y: (whatever you want)
repeat until <(x position) = (end x)>
move (10) steps
end
delete this clone
end
if you want it to scroll vertically , just replace the start and end x with start and end y , and x positions with y positions
Last edited by bruno146 (May 11, 2023 10:30:48)
- Hollowness
-
Scratcher
56 posts
Scrolling with clones
I don't know if the above posts worked for you but since it sounds like you already have some of the clone scripts figured out, this is what I would do.
Create new variables “SCROLL DX” and “SCROLL DY”. (The D stands for delta)
Go to the backdrop or really any sprite, and add the following scripts.(DO NOT set to run without screen refresh)
Now go to the forever loop in your ‘when i start as clone’ event, and add this
Hope this helps
Create new variables “SCROLL DX” and “SCROLL DY”. (The D stands for delta)
Go to the backdrop or really any sprite, and add the following scripts.(DO NOT set to run without screen refresh)
when green flag clicked
forever
Record Scroll Change (SCROLL X) (SCROLL Y)
end
define Record Scroll Change (scroll.x) (scroll.y)
wait (0) secs
set [SCROLL DX v] to ((SCROLL X) - (scroll.x))
set [SCROLL DY v] to ((SCROLL Y) - (scroll.y))
Now go to the forever loop in your ‘when i start as clone’ event, and add this
change x by (SCROLL DX)
change y by (SCROLL DY)
Hope this helps
- Discussion Forums
- » Help with Scripts
-
» Scrolling with clones