【发布时间】:2010-06-16 07:29:01
【问题描述】:
制作像“涂鸦跳跃”这样的游戏需要 opengl 或核心动画就足够了?应该从哪里考虑使用opengl?
【问题讨论】:
标签: iphone objective-c cocoa-touch
制作像“涂鸦跳跃”这样的游戏需要 opengl 或核心动画就足够了?应该从哪里考虑使用opengl?
【问题讨论】:
标签: iphone objective-c cocoa-touch
我已经玩了几个星期的小型等距 3D 游戏了。我第一次使用 CA,但切换到 OpenGL。我的理由是:
对我来说,这让 OpenGL 成为一项值得投资的项目。
YMMV
【讨论】:
这是我个人的看法, 我认为用CA制作游戏很复杂。 我推荐 OpenGL。
在基于 OpenGL 的项目中,您应该逐帧手动绘制和移动元素以制作动画。 它需要比 CA 更长的代码,但您可以轻松同步屏幕和游戏状态。 使用CA很难严格同步图形和游戏。
当然,OpenGL 的性能比 CA 好得多。 而且,学习 OpenGL 并不难!
【讨论】:
如果您在 opengl 和 iphone 开发方面没有任何现有经验,我建议您先使用quartz 开发您的基本游戏,因为它会为您提供最简单的学习曲线。根据您的需要,它甚至可能在最终游戏中表现得足够好。
这是一个简单的自定义视图,它使用 30fps 动画循环渲染单个精灵。
@interface GameView : UIView{
NSTimer* animTimer;
UIImage* sprite;
}
- (void)animate:(NSTimer*)theTimer;
@end
@implementation GameView
- (id)initWithFrame:(CGRect)frame {
if((self=[super initWithFrame:frame])){
sprite=[[UIImage imageNamed:@"sprite.png"] retain];
animTimer=[[NSTimer scheduledTimerWithTimeInterval:1.0/30.0
target:self selector:@selector(animate:)
userInfo:nil repeats:YES] retain];
}
return self;
}
- (void)animate:(NSTimer*)theTimer{
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
[sprite drawAtPoint:CGPointMake(0,0)];
}
@end
【讨论】: