按设定的时间间隔创建 UIImageView?
所以我正在为一堂课制作一个简单的基于 UIKit 的 iphone 游戏。如果有人熟悉的话,它与 Sky Burger 类似。如果没有,游戏中的物体将从屏幕顶部掉落,并且屏幕底部的加速计控制的角色将接住它们。
我已经完成了游戏循环和角色移动。我知道如何为 ImageViews 下落设置动画(如果我可以创建它们的话)。我只是不知道如何创建每 1-3 秒左右创建一次的多个 UIImage 视图。
如果有人能给我指出正确的方向,或者对我应该开始寻找的地方有任何建议,我将不胜感激。
另外,如果我不清楚,请告诉我,我会尽力详细说明。
So I'm making a simple UIKit based iphone game for a class. It's similar to Sky Burger if anyone is familiar. If not, the game will be objects falling from the top of the screen and there will be a character that is controlled by the accelerometer at the bottom of the screen that will catch them.
I have the game loop and character movement all done. I know how to animate the ImageViews falling (if i could create them that is). I just cant figure out how to create multiple UIImage views that are created every 1-3 seconds or so.
If anyone could point me in the right direction or has any suggestions of places where I should start looking it would be greatly appreciated.
Also if I'm being unclear just let me know and I'll try to elaborate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个 NSTimer,每隔 1-3 秒左右安排一次,然后在计时器的操作方法中创建图像视图 (
[[UIImageView alloc] initWithImage:]
),定位它们并将它们添加到您的主视图中 (-addSubview:
)。不要忘记删除那些不再需要的图像视图,否则您将很快建立太多视图,导致应用程序崩溃。
Create an
NSTimer
, schedule it every 1-3 seconds or so, and in the timer's action method, create the image views ([[UIImageView alloc] initWithImage:]
), position them and add them to your main view (-addSubview:
).Don't forget to remove those image views you no longer need or you'll quickly build up so many views that your app will crash.