Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Rotating separate sprites
- peacock-en-pointe
-
1 post
Rotating separate sprites
I am having trouble with rotating sprites separately for a school project. I need to be able to click on a sprite and have it rotate, without rotating the others. ex: imagine there are 3 sprites, and you can drag them like a puzzle. But also just like a puzzle, you need to rotate them to make them fit together. But, if i give them the option to do something like this:
when [ right] key pressedthen it makes them ALL turn, when i just want to be able to click one, have that one rotate, then click another and have ONLY that other one rotate. anyone know how to do this?
turn cw (15) degrees
when [ left] key pressed
turn ccw (15) degrees
Last edited by peacock-en-pointe (June 5, 2020 00:36:18)
- HufflePuffRules1009
-
100+ posts
Rotating separate sprites
Change the code for each sprite, like this: I am having trouble with rotating sprites separately for a school project. I need to be able to click on a sprite and have it rotate, without rotating the others. ex: imagine there are 3 sprites, and you can drag them like a puzzle. But also just like a puzzle, you need to rotate them to make them fit together. But, if i give them the option to do something like this:when [ right] key pressedthen it makes them ALL turn, when i just want to be able to click one, have that one rotate, then click another and have ONLY that other one rotate. anyone know how to do this?
turn cw (15) degrees
when [ left] key pressed
turn ccw (15) degrees
Sprite 1
when [right v] key pressed
turn cw () degrees
when [left v] key pressed
turn ccw () degrees
Sprite 2
when [r v] key pressed
turn cw () degrees
when [l v] key pressed
turn ccw () degrees
Sprite 3
when [a v] key pressed
turn cw () degrees
when [b v] key pressed
turn ccw () degrees
- super_crazy
-
100+ posts
Rotating separate sprites
What you could do instead, if you want to use the arrow keys for all the sprites, is create a variable and set it to a unique value when a sprite is clicked. Then when you rotate the sprites first make sure that the variable you created is equal to the unique value for that sprite.
Below is an example:

Below is an example:
Do this for all of your sprites but make sure to change the ‘australia’ to another name. For example in the Africa sprite you would do the following:// In the 'Australia' sprite
when this sprite clicked
set drag mode [draggable v] :: sensing
set [clicked v] to [australia] // You will need to create this variable. You can name it whatever you like
// Then in the same sprite
when [right v] key pressed
if <(clicked) = [australia]> then // This checks if the 'Australia' sprite was the last one clicked
turn cw (15) degrees // If it was then only this sprite will rotate
end
when [left v] key pressed
if <(clicked) = [australia]> then
turn ccw (15) degrees
end
That should achieve what you want. Hopefully that helped// In the 'Africa' sprite
when this sprite clicked
set drag mode [draggable v] :: sensing
set [clicked v] to [africa]
// Then in the same sprite
when [right v] key pressed
if <(clicked) = [africa]> then
turn cw (15) degrees
end
when [left v] key pressed
if <(clicked) = [africa]> then
turn ccw (15) degrees
end

Last edited by super_crazy (June 5, 2020 05:08:04)
- deck26
-
1000+ posts
Rotating separate sprites
Or just add an ‘if touching mouse pointer’ around the rotate block so only the sprite currently touched by the mouse will turn. Having different keys for turning different sprites is needlessly complicated.
- Discussion Forums
- » Help with Scripts
-
» Rotating separate sprites