I know generally how to make a sprite jump. But it usually isn't that clean. Does anyone know any tips or things I should know first? Any easier or efficient methods?
edit: not sure if it's relevant, but the sprite is a stickman
I know generally how to make a sprite jump. But it usually isn't that clean. Does anyone know any tips or things I should know first? Any easier or efficient methods?
edit: not sure if it's relevant, but the sprite is a stickman
thanks! just curious, how is a for I block better than a repeat (____) block?
for
has an upvar (an internal variable exposed to the programmer) for the number of times the script has looped. repeat
works well, but if you wanted an iteration variable, you would have to set one at the beginning and then change it by 1. for
is just more convenient for this use case.
That actually makes the jump speed up towards the peak of the jump and then suddenly switch to going down. Instead, it would be smoother to do this:
I intentionally left parts out for @nathenaelhailu08 to experiment and learn
Or, simplifying it further, you could just do this:
when [space V] key pressed for (i) = (10) to (-10) { change y by (i)
To put it simply, convenience.
There's a three big loop blocks (excluding the forever loop) that are used for different things (or technically four with recursive blocks):
,
, and
.
They all act somewhat similarly, but are helpful for different tasks.
Repeat Loop
A normal repeat loop is the baseline. It's simple, and is often used. For example, let's say you want a player to move along the screen, maybe 100 steps. You could just use move (100) steps, but that would just teleport the player to the end. Instead, you want an animation. This is when the repeat loop is used. Using the repeat loop, you can make something like this:
Forever Loop and Repeat Until Loop
I didn't mention these in the big three, but I listed them here because they are kind of similar to the repeat loop.
The forever loop and until loop have pretty similar use cases. A forever loop is self explanatory; use it when you want to repeat something forever, like the player's main movement script for a game.
An until loop is kind of like a forever loop, and kind of like a repeat loop. It's used when you know there will be some sort of end point for the loop, but you don't know how many times it needs to repeat until that happens, hence the name. This might be used in the script for a projectile; you want it to move until it hits something or goes off screen.
For Loop
A for loop is similar to a repeat loop, but is used in more complex scenarios. For example, let's say that instead of moving at a constant speed, you want something to start by moving slowly, then accelerate, or start by moving quickly, then deaccelerate. (Like a player jumping, in your use case.)
This is where for loops come in. You can set a range of numbers for the loop to go between. For example, by default, with , with the numbers from 1 to 10. The i in the block can be dragged out, and used in scripts. For example, with the acceleration scenario I gave before, this is a way that could be done:
For Each Loop
The for each loop is very similar to the for loop, but instead of dealing with a range of numbers, it handles any list you give it. For example, let's say you have a list of words, and you want to print all of them out. You could do that like this:
So that's basically it for loops. If you have further questions, feel free to let me know!
(Also, for those of you who are curious, the transparent sprites are there to show movement. They weren't created from the scripts, I threw some stuff in the loops to make them do that as the sprite moves.)
You summed it up perfectly. Thank you for all the help!
first of all, great post. should be added to FAQ for beginners.
However, I have one question:
how did the sprites become less transparent over time?
Not the maker, but I'm guessing they don't actually become less transparent, its just to show that the sprite is moving. Kind of like a blur effect.
As @nathenaelhailu08 said, I did that myself. It's just to emphasize the movement of the sprite.
In fact, all of the images weren't exactly the results of the code. All of them had that fading sprite to show movement, but also with the acceleration example, the image is an entirely different range of values. I changed the range so that you could still see the acceleration, and could actually see the initial movement (as the 1 to 10 values had some of the earlier ones on top of each other.)