Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to make clones spawn in different positions
- egashu
-
100+ posts
how to make clones spawn in different positions
I am making a scroller game and I am trying to make these little dots go to random position and stay there but keep making clones (with scroll x but I already am done with the scroll x part) I just need help with the clones staying in the same position please help!!!

- egashu
-
100+ posts
how to make clones spawn in different positions
thanks!!! I'll see if that works

- deck26
-
1000+ posts
how to make clones spawn in different positions
If it's a scroller each clone needs to know where it is in ‘real world’ terms. It can then apply scrollx/y to that position to give the current screen position.
- deck26
-
1000+ posts
how to make clones spawn in different positions
I assume you don't understand my last post. I'm assuming you're scrolling around a ‘real world’ so the Scratch screen is showing you one part of that world which changes as you move around. I'm also assuming the clones might be anywhere in that real world and you want them to maintain their real world position so they only appear when you happen to be in the right area.
So if the screen was 10 x 10 units and the world was 100 units by 100 units you're only seeing a small area of the world. When you move around you'd find clones which were positioned according to real world coordinates and are only shown on screen when the screen area includes that real world position. If the screen is centred at real world 25,35 you'd only see clones in the range x=20 to 30, y=30 to 40. I've simplified things here - you'd probably be working with pixels and the screen being 480 x 360 with the real world being scaled up in the same way.
If that is all correct.and the clones don't move then you can work out the screen coordinates by adjusting real world coordinates by scrollx/y. If the adjusted values fall within the normal screen range you show the clone in the adjusted position. In my example, the screen perhaps starts at 5, 5 with scrollx/y=0. As you move right scrollx becomes negative so when the screen is at 25,35 the scrollx/y values are -20 and -30. If you have a clone at 27, 35 the screen-x value would be 27 - 25 = 2 and screen-y would be 35 - 30 = 5 which would place the clone correctly relative to the screen centre - 2 units right of centre on the centre line vertically. Move the player another two pixels right and the screen would be at 27, 35 which matches the clone's position and the clone's adjusted position would be 0,0 as required.
So if the screen was 10 x 10 units and the world was 100 units by 100 units you're only seeing a small area of the world. When you move around you'd find clones which were positioned according to real world coordinates and are only shown on screen when the screen area includes that real world position. If the screen is centred at real world 25,35 you'd only see clones in the range x=20 to 30, y=30 to 40. I've simplified things here - you'd probably be working with pixels and the screen being 480 x 360 with the real world being scaled up in the same way.
If that is all correct.and the clones don't move then you can work out the screen coordinates by adjusting real world coordinates by scrollx/y. If the adjusted values fall within the normal screen range you show the clone in the adjusted position. In my example, the screen perhaps starts at 5, 5 with scrollx/y=0. As you move right scrollx becomes negative so when the screen is at 25,35 the scrollx/y values are -20 and -30. If you have a clone at 27, 35 the screen-x value would be 27 - 25 = 2 and screen-y would be 35 - 30 = 5 which would place the clone correctly relative to the screen centre - 2 units right of centre on the centre line vertically. Move the player another two pixels right and the screen would be at 27, 35 which matches the clone's position and the clone's adjusted position would be 0,0 as required.
- IamNotlegend
-
3 posts
how to make clones spawn in different positions
Try this for a steady movement and not go off border you want
Last edited by IamNotlegend (April 15, 2022 18:13:54)
- The-Molten-Freddy
-
500+ posts
how to make clones spawn in different positions
If you want to spawn a clone in a different position every time, this is what you do. I am making a scroller game and I am trying to make these little dots go to random position and stay there but keep making clones (with scroll x but I already am done with the scroll x part) I just need help with the clones staying in the same position please help!!!
- IamNotlegend
-
3 posts
how to make clones spawn in different positions
goodIf you want to spawn a clone in a different position every time, this is what you do. I am making a scroller game and I am trying to make these little dots go to random position and stay there but keep making clones (with scroll x but I already am done with the scroll x part) I just need help with the clones staying in the same position please help!!!
- ronnierooninja
-
1 post
how to make clones spawn in different positions
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
- _turtle64
-
100+ posts
how to make clones spawn in different positions
Dont necropost. This question is almost 4 years old. .
- Discussion Forums
- » Help with Scripts
-
» how to make clones spawn in different positions