Java:如何延迟由形状表示的类的对象的“跳跃”?

huangapple go评论78阅读模式
英文:

Java: How to delay an object of a class represented by a shape from 'jumping'?

问题

以下是您要求的翻译部分:

问题是:编写一个名为jump()的公共类方法,不返回任何内容。它应使作为参数传递的巫师(由三角形表示的类的实例)向上跳一个单元格位置,然后返回到其原始单元格。

为了正确跟踪巫师的运动,您需要减慢动画速度。为了帮助您做到这一点,我们在WizardController类中提供了一个名为delay()的类方法。

例如,如果您想要100毫秒的延迟,您将在代码的适当位置插入以下语句:

请记住,在您编写的每个方法的适当位置使用delay()来为巫师添加动画效果。

这是我的代码:

public static void jump(Wizard wizard1)
{
    wizard1.upBy(1);
    WizardController.delay(10000);
    wizard1.downBy(1);
    WizardController.delay(10000);
}

上述代码可以编译,但当我执行以下代码以进行测试时,'triangle'形状会在没有延迟的情况下迅速跳动。即使我在代码中添加了延迟。如何正确延迟,以便'triangle'等待,然后向下移动一个。非常感谢。

Wizard w = new Wizard(OUColour.PINK, 1);
Triangle t = w.getPersona();
WizardController.jump(w);
英文:

So the question is: Write a public class method jump() that returns nothing. It should make the wizard(instance of the class represented by a triangle) passed as argument jump up one cell position from its current cell then return to its original cell.

In order to follow the motion of the wizards properly you will need to slow the animation down. To help you do this we have provided a class method delay() in the WizardController class.

e.g. If you want a delay of 100 ms you would insert the following statement at the appropriate point in your code.:

Remember to use delay() at the appropriate point in each of the methods you write to animate the wizards.'

heres my code:

public static void jump(Wizard wizard1)
  {
wizard1.upBy(1);
WizardController.delay(10000);
wizard1.downBy(1);
WizardController.delay(10000);
}

The code above compiles but when I execute the following to test it.. the 'triangle' shape jumps very quickly without a delay. eventhough I have in my code added delay.How can I delay it properly so 'triangle' waits and then moves one down. Many thanks

Wizard w = new Wizard(OUColour.PINK, 1);
Triangle t = w.getPersona();
WizardController.jump(w);

答案1

得分: 1

所以跳跃过程是这样的。巫师立即向上跳跃,等待延迟结束,立即向下跳跃,再次等待延迟结束。这是因为程序按照编写的顺序执行代码。

为了解决这个问题并实现流畅的跳跃,您需要在upBy()方法中进行更改,以便在增加x/y值之间有延迟。

英文:

So the jump goes like this. Wizard jumps instantly up, waits out the delay, instantly goes down, waits out the delay. Thats because the program excecutes the code in the sequence written.

In order to solve it and have a fluent jump you have to make changes in the upBy() method, so theres a delay in between increments of x/y value.

huangapple
  • 本文由 发表于 2020年4月4日 18:03:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/61026483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定