平滑划痕中的精灵运动

发布于 2024-12-03 00:54:37 字数 99 浏览 0 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

明月夜 2024-12-10 00:54:37

我知道这是一个老问题。但如果有人正在寻找解决方案,请查看这个临时项目: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.

如此安好 2024-12-10 00:54:37

您可以这样做:

When flag pressed
forever
  if (right arrow pressed?) then
    change xs by 1
  xs = xs * 0.8
  change x by (xs)

每次检查是否按下右箭头,如果是,则将变量 xs 更改 1。随后,它将 xs 乘以 0.8,因此该值会稍微衰减。

然后它通过 var xs 更改精灵的 x。

You can do this:

When flag pressed
forever
  if (right arrow pressed?) then
    change xs by 1
  xs = xs * 0.8
  change x by (xs)

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.

樱花坊 2024-12-10 00:54:37

借助 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. :)

笑忘罢 2024-12-10 00:54:37

“箭头未按下”

你可以这样做,直到按下箭头时出现
重复
移动(或滑行)
直到没有按下箭头

,否则它将不会以设定的时间间隔检查按键按下情况,从而使移动更加平滑。

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.

晨曦÷微暖 2024-12-10 00:54:37

这是一个老东西,但却是一个好东西,正如其他人建议的那样,您需要不断检查该键是否仍然被按下,并重复您需要的任何操作,直到不再按下该键为止。像这样:

“重复一个动作,直到不再按下某个键”

这是因为当您按住某个键时,计算机会等待短暂的暂停,然后才接受您确实希望重复按下该键。

这是称为“去抖动”(或“节流”)输入的概念的组合,可用于所有类型的电子和计算。如果它没有做到这一点,那么您的打字就会看起来像这样。

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:

repeating an action until a key no longer pressed

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 (or throttling) 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.

迷迭香的记忆 2024-12-10 00:54:37

一种方法是使用变量和自定义块来生成参数以平滑运动。添加一个名为 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.

七禾 2024-12-10 00:54:37

您可以为平滑 x 移动执行此操作:

forever
change x by (([amount] - (x position)) / [divide])

其中“量”是您想要移动的量,“除”是移动的平滑程度。
(对 y 进行同样的平滑处理)

或者您也可以平滑 x 和 y 移动:

forever
go to x: (([amount] - (x position)) / [divide]) y: (([amount] - (x position)) / [divide])

此外,您还可以使精灵平滑地滑向鼠标:

forever
go to x: (((mouse x) - (x position)) / [divide]) y: (((mouse y) - (x position)) / [divide])

You could do this for smooth x move:

forever
change x by (([amount] - (x position)) / [divide])

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:

forever
go to x: (([amount] - (x position)) / [divide]) y: (([amount] - (x position)) / [divide])

Also, you can make the sprite glide smoothly to the mouse:

forever
go to x: (((mouse x) - (x position)) / [divide]) y: (((mouse y) - (x position)) / [divide])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文