How do you move an object up down and diagonally
Offline
when an object is on a particular x and y (ex. x=-92, y=102), how do i hide or show that object
Offline
bobbyjenks wrote:
when an object is on a particular x and y (ex. x=-92, y=102), how do i hide or show that object
if<xposition =|92|> and <yposition = |102|>
hide
Hope that helps
Offline
To move an object upwards, add a number to the Y position. For example:
[blocks]<when[ up arrow ]key pressed>[/blocks]
[blocks]<change y by( 10[/blocks]
To move an object downwards, subtract a number from the Y position.
[blocks]<when[ down arrow ]key pressed>[/blocks]
[blocks]<change y by( -10 [/blocks]
Here are the equations for making an object move diagonally.
X pos. - 10, Y pos. + 10 (North-west)
X pos. + 10, Y pos. - 10 (South-east)
X pos. + 10, Y pos. + 10 (North-east)
X pos. - 10, Y pos. - 10 (South-west)
You can change the number 10 to any number you wish. If you use a small number such as 5, the object won't move very far, but if you use a big number like 50, it will move very far. The number 10 makes it move an in-between sort of distance.
If you want a sprite to move in a certain direction after pressing the arrow keys, or something like that, you need this script:
[blocks]<when[ left arrow ]key pressed>[/blocks]
[blocks]<change x by( -5 [/blocks]
If you want the sprite to go to a certain spot on the screen after pressing a button, receiving a message, etc., you'd use the "go to" block.
[blocks]<when[ cake ]clicked>[/blocks]
[blocks]<go to x pos. of cake )y
pos. of cake [/blocks]
[blocks]<say[ DON'T TOUCH THAT! [/blocks]
However, this block will just make the object "teleport" to the location mentioned. In other words, it will just suddenly appear wherever you told it to go.
If you want it to look like it actually moved over to that place, you should use the "glide" instruction. Here is a script for making a sprite "fly" over to a certain place on the stage.
[blocks]<when I receive[ lift off[/blocks]
[blocks]<glide( 1 )secs to x 2 )y
142[/blocks]
The more seconds you choose, the slower the sprite will glide. So, if the sprite was a rocket, like in the above example, you would type in 1 second or less. (Yes, you can do decimal numbers.) If the sprite was a tractor, you would choose something around 10 seconds.
I hope this information helped you with whatever project you're working on, and I hope it will be useful for your future projects too. Happy Scratch-ing!
Offline