Discuss Scratch

Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

Hi,

Could anyone please tell me how to make sprites smoothly, for example my project is a car and at the moment I have it set to

Change x by -10 to go left

Change x by 10 to go right

But when I do this the car moves in steps.
zanzolo
Scratcher
66 posts

How to make Sprites Move Smoothly

One way would be something like this: It moves by one pixel at a time, and does it 10 times

whenclickedforeverifkeyleft arrowpressed?thenrepeat10changexby-1ifkeyright arrowpressed?thenrepeat10changexby1
lifesalibrary4me
Scratcher
43 posts

How to make Sprites Move Smoothly

I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.
zanzolo
Scratcher
66 posts

How to make Sprites Move Smoothly

lifesalibrary4me wrote:

I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.

Glides are great for somethings.

I don't like them for games though because once you start a glide you pretty much have to finish it.
Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

The first post works quite well but it is too slow for what I am doing, is their any way to have the same thing but faster?
AonymousGuy
Scratcher
1000+ posts

How to make Sprites Move Smoothly

Lachiepower0402 wrote:

The first post works quite well but it is too slow for what I am doing, is their any way to have the same thing but faster?
Try the following:
whenclickedforeverifkeyright arrowpressed?thenchangexby10ifkeyleft arrowpressed?thenchangexby-10
The sprite will jump by 10 pixels each time, but it should look smooth because it is in a continuous loop.

The sprite can go faster or slower by changing the amounts.
Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

Thanks that works perfectly, but I have another question. In this same game the car passes brick walls that are moving past the car, how can I make it so that when the car misses a brick wall their is a score that shows this?
AonymousGuy
Scratcher
1000+ posts

How to make Sprites Move Smoothly

It depends on how the walls are moving. Is the car sprite staying in the center of the screen, with the wall sprites moving? If so, then you can do something like this:
whenclickedIn the car spritesetScoreto0This is a variable. If you don't know what this is, refer to bottom section.foreverifx positionofbrick_wall<xpositionthenchangeScoreby1
Variable explanation: If you don't yet know what a variable is, you can create one by going to the Data tab and clicking “Create Variable”, then naming it what you want (in this case, Score.) Variables are basically just values that can be rewritten and reused, so their value will be read and used instead of a manually input value. (If that makes sense.)

Also, if this isn't the method your game is using, please say so, as I can give a more helpful script. It will probably be somewhat similar to this script anyways.
Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

No sorry that didn't work, the car sprite moves left and right along the screen and a wall comes down from the top of the screen to the bottom, hides, reappers at the top in a different spot and goes down again and the car has to avoid the wall otherwise a background comes up saying game over. So for every wall the car doesn't hit I want the score to go up by one. What happened just then was when I avoided a wall the score when up very quickly to a high number i.e. 17931724.
AonymousGuy
Scratcher
1000+ posts

How to make Sprites Move Smoothly

Lachiepower0402 wrote:

No sorry that didn't work, the car sprite moves left and right along the screen and a wall comes down from the top of the screen to the bottom, hides, reappers at the top in a different spot and goes down again and the car has to avoid the wall otherwise a background comes up saying game over. So for every wall the car doesn't hit I want the score to go up by one. What happened just then was when I avoided a wall the score when up very quickly to a high number i.e. 17931724.
Okay, so I think that means that the x position blocks just have to be changed to y position blocks:
whenclickedIn the car spritesetScoreto0This is a variable. If you don't know what this is, refer to bottom section.foreverify positionofbrick_wall<ypositionthenchangeScoreby1


Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

That is a lot better, but the score doesn't just go up by 1, when the wall passes the car the scores goes up until the wall disappears, so the wall moves from the top goes down and passes the car as i avoid it and the score goes up when moving past the car and then the wall moves to the top again.
AonymousGuy
Scratcher
1000+ posts

How to make Sprites Move Smoothly

Add the following after the block changing the score:
waituntilnoty positionofbrick_wall<yposition
Lachiepower0402
New Scratcher
7 posts

How to make Sprites Move Smoothly

That works, thank you.
AonymousGuy
Scratcher
1000+ posts

How to make Sprites Move Smoothly

Lachiepower0402 wrote:

That works, thank you.
You're welcome!
Ninjai
Scratcher
2 posts

How to make Sprites Move Smoothly

LOL
Sewell1706
Scratcher
1 post

How to make Sprites Move Smoothly

wow,u guys are a pretty smart pair
lederniersamourai
Scratcher
500+ posts

How to make Sprites Move Smoothly

zanzolo wrote:

lifesalibrary4me wrote:

I just use the glide __ seconds to x:__ y:__, but that’s just because I do animations. If you are doing a game it would be harder.

Glides are great for somethings.

I don't like them for games though because once you start a glide you pretty much have to finish it.
glide can be interrupted any time: just put them under an “event hat” such as this one:
whenIreceiveglide1glidesecvarsecstox:xvary:yvar
Just set variable to new values to glide on another path and schedule, and then use neutral values (i.e. 0 secs, current x value and current y value) for stopping gliding,
Cyoce
Scratcher
500+ posts

How to make Sprites Move Smoothly

whenclickedforeversetXtowhereyouwantthesprite'sXtobesetYtowhereyouwantthesprite'sYtobeifsomethingcausesittostoptheglidethensetXtoxpositionsetYtoypositionelsechangexbyX-xposition*absofX-xposition/absofX-xposition+absofY-YpositionchangeybyY-yposition*absofY-Yposition/absofX-xposition+absofY-Yposition
-appletree-
Scratcher
43 posts

How to make Sprites Move Smoothly

whenclickedforeverifkeyright arrowpressed?thenchangexby4
REPUS
Scratcher
18 posts

How to make Sprites Move Smoothly

This script will make a sprite glide to a place ten steps over, instead of simply reappearing in a place ten steps over.
when Left arrowkeypressedglide0.3secstox:-10+xpositiony:ypositionwhen Right arrowkeypressedglide0.3secstox:10+xpositiony:yposition

Last edited by REPUS (Nov. 11, 2014 02:52:04)

Powered by DjangoBB