平滑划痕中的精灵运动
如何在 Scratch 中平滑动画?主要是,我希望当您按住右箭头时,它会向右移动,而不会出现任何明显的抖动。另外,当你按住箭头时,刮擦会让你等待一秒钟才能重复。我怎样才能平滑这些东西?
How can I smooth out animations in Scratch? Mainly, I want it such that when you press and hold the right arrow, it goes right without any noticeable jittering. Plus, scratch makes you wait a second to repeat when you hold an arrow. How can I smooth this stuff out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我知道这是一个老问题。但如果有人正在寻找解决方案,请查看这个临时项目:http://scratch.mit。 edu/projects/276298/
只需添加永远循环并在该循环内检查是否按下了箭头键。如果是——移动。
这样您就不会依赖键盘重复率。
I know it's an old question. But in case somebody is looking for a solution, check out this scratch project: http://scratch.mit.edu/projects/276298/
Just add forever loop and inside this loop check if arrow key is pressed. If it is - move.
This way you won't be dependent on keyboard repeat rate.
您可以这样做:
每次检查是否按下右箭头,如果是,则将变量
xs
更改 1。随后,它将 xs 乘以 0.8,因此该值会稍微衰减。然后它通过 var
xs
更改精灵的 x。You can do this:
That checks everytime if the right arrow is pressed, and if yes, it changes the variable
xs
by one. Later, it multiplies xs by 0.8, so the value sightly decays.Then it changes the sprite's x by the var
xs
.借助 Scratch,您可以使用长距离或间隔的
Glide
获得非常平滑的运动。然而,这种方法的缺点是滑翔操作必须在精灵可以进行任何感测(例如边缘或碰撞检测)之前完成。这通常是不希望的。您所说的按下按键时的小延迟实际上与键盘的重复率直接相关。当您按下键盘上的某个键时,会发送该按键事件,但在重复开始之前会有一个小的延迟。如果您能找到一种方法来更改系统键盘重复率,这将延续到 Scratch 中。
在 Scratch 中可以进行的优化程度是有限的。毕竟,它是一个非常基本(但非常有趣)的入门级编程环境。 :)
With Scratch, you can get very smooth motion using
Glide
with long distances or intervals. However, the disadvantage of this method is that the Glide operation must finish before the sprite can do any sensing, such as edge or collision detection. This is often undesirable.The small delay that you are talking about when you press a key, is actually directly tied to the repeat rate of your keyboard. When you press a key on your keyboard, that key event is sent, but then there is a small delay before the repeat kicks in. If you can find a way to change your system keyboard repeat rate, this would carry over into Scratch.
There is a limit to how much optimizing you can do in Scratch. It is, after all, a very basic(but very fun), entry-level programming environment. :)
“箭头未按下”
你可以这样做,直到按下箭头时出现
重复
移动(或滑行)
直到没有按下箭头
,否则它将不会以设定的时间间隔检查按键按下情况,从而使移动更加平滑。
You could do until "arrow not pressed"
when arrow pressed
repeat
move (or glide)
until not arrow pressed
then it will not check key pressing at set intervals, making the move smoother.
这是一个老东西,但却是一个好东西,正如其他人建议的那样,您需要不断检查该键是否仍然被按下,并重复您需要的任何操作,直到不再按下该键为止。像这样:
这是因为当您按住某个键时,计算机会等待短暂的暂停,然后才接受您确实希望重复按下该键。
这是称为“去抖动”(或“节流”)输入的概念的组合,可用于所有类型的电子和计算。如果它没有做到这一点,那么您的打字就会看起来像这样。
This is an oldie but a goodie, and as others have suggested you need to keep checking that the key is still pressed and repeat whatever action you need until it's not pressed any more. Like so:
This is because when you hold down a key the computer will wait a short pause before accepting that you really do want the the key press to be repeated.
This is a combination of concepts called
debouncing
(orthrottling
) an input and is useful on all kinds of electronics and computing). If it didn't do that allll ooofff yoourr ttyping wwoould look likke thhhis.一种方法是使用变量和自定义块来生成参数以平滑运动。添加一个名为 speed x 的变量,并使用 speed X 永久更改 X。我没有任何快照或示例,但您可以使用自定义块中的脚本来平滑滑动它。
One way you can do that is use variables and custom blocks to make arguments to smooth out motion. Add a variable called speed x and use a forever change X by speed X. I don't have any snapshots or examples, but you can use scripts in the custom block to smoothly glide it.
您可以为平滑 x 移动执行此操作:
其中“量”是您想要移动的量,“除”是移动的平滑程度。
(对 y 进行同样的平滑处理)
或者您也可以平滑 x 和 y 移动:
此外,您还可以使精灵平滑地滑向鼠标:
You could do this for smooth x move:
Which 'amount' is how much that you want to move and 'divide' is how smooth is that.
(Do the same with smoothing y)
Or you can also smooth x and y move:
Also, you can make the sprite glide smoothly to the mouse: