用于各种屏幕保护应用程序的 Java 基本动画

发布于 2024-08-09 09:35:43 字数 400 浏览 5 评论 0原文

我被分配制作一个动画屏幕保护程序作为我的高级编程课程的编程项目。目标是在未装饰的全屏框架内放置多个移动组件,但我将逐步进行,一次只处理一个组件。

这是到目前为止我的源代码: http://pastebin.com/dc722188

请随意注释掉任何涉及文件操作的部分,它们不是目前相关。

现在,我遇到的问题是,显然程序将我的 LogoComponet 识别为包含整个框架(即使它不应该如此),因此立即触发碰撞条件,导致我的徽标对象突然开始癫痫发作。我根本不知道是什么原因造成的,即使手动设置组件的边界也不起作用,而明天到期的事实对我的情况根本没有帮助。

那么,呃,请帮忙? .___。

I was assigned to make an animated screensaver as a programming project for my Advanced Programming course. The objective is to have several moving components inside an undecorated, fullscreen frame, but I'm going step-by-step and doing it one component at a time.

Here's my source code so far:
http://pastebin.com/dc722188

Feel free to comment out any part involving file operations, they're not relevant for now.

Now, the issue I have here is that apparently the program recognizes my LogoComponet as encompassing the entire frame (even though it's not supposed to), and thus the conditions for collision are triggered immediately causing my logo object to suddenly start having seizures. I have no idea what's causing this at all, an even manually setting the bounds for the component won't work, and the fact that this is due tomorrow isn't helping my case at all.

So, uh, help, please? .___.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

素食主义者 2024-08-16 09:35:43

首先,您粘贴的代码在twoSquareComponent 中的构造函数命名不正确。问题出在你的动画方法上。当您进行检查以更改方向时,您会更改方向,但下一个呼叫会移回到您所在的位置。您需要某种方法来跟踪当前方向。

举个例子,如果你穿过一侧,你的 dx 是 10,当前的 x 是 11,你会移动到 1,然后下一个动画调用会让你回到 11,然后回到 1,等等。它只是重复这个,因此出现癫痫效果你描述。我会把这个留给你,因为它是家庭作业:)。但这是你的问题你可能想存储当前方向,并且在再次出界之前不要改变。

祝你好运

First, the code you pasted has the constructor named improperly in the twoSquareComponent. The problem is in your animate method. When you make your checks to change direction you change the direction, but the next call moves back to where you where. You need some way to track current direction.

As an example if you cross the side and your dx is 10 and current x is 11 you move to 1 and then the next animate call puts you back at 11, and then previous to 1, etc. It just repeats this hence the seizure effect you describe. I'll leave this to you as it's homework :) . but that is your problem You probably want to store current direction, and not change until you go out of bounds again.

Good Luck

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