Making a 2d game with Quartz

Discussion in 'iOS Programming' started by MasterObiWan, Jan 31, 2009.

  1. MasterObiWan macrumors newbie

    Jan 12, 2009
    I have tried doing this and the outcome was not good. It works fine in simulator, but when trying to run on a device it is unplayably slow (the sprites will barely move).

    My question is if I had made my game in OpenGL would it run properly? Or does this have something to do with my code, and even if I did rewrite it in OpenGL would it be the same outcome?
  2. admanimal macrumors 68040

    Apr 22, 2005
    This question is virtually impossible to answer without knowing what your code looks like, although generally speaking you should get better performance from OpenGL.
  3. MasterObiWan thread starter macrumors newbie

    Jan 12, 2009
    So you are saying it is possible to make a playable game in quartz.

    I'd like to paste my entire code , but then someone might figure out what I'm trying to make. I hope this will be enough to figure it out:

    What I think might be causing it to run slow:

    1)All my methods are written in the same file as my code. So all i have to do is do [self someMethod] to call my method. Do I have to release a method everytime I use one?

    2)A timer thread runs every 0.01 calling a bunch of methods, this basically makes my entire program animate and run. example:

    timer = [NSTimer scheduledTimerWithTimeInterval:(0.01) target:self selector:mad:selector(onTimer:) userInfo:nil repeats:YES];

    In method :eek:nTimer {
    [self moveEnemies];
    [self movePlayer];
    bla bla etc etc...

    This is how I usually do it in Java btw.
  4. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    If you have more than just a few sprites, OpenGL is tons faster than Quartz 2D on the iPhone.

    It almost seems like the iPhone does not have any actual 2D drawing capability, but converts every 2D command, view or layer into OpenGL textures and such, hidden behind the back, before doing any rendering. Might as well go straight to OpenGL if you can.
  5. admanimal macrumors 68040

    Apr 22, 2005
    It wouldn't be surprising if that was the case, since I'd guess that real OS X uses OpenGL as the bottom layer for most of its drawing as well.
  6. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    Why run your animation at 100 frames a second? Try 30 fps, that might make a big enough difference to maek your game playable.

    b e n
  7. detz macrumors 65816

    Jun 29, 2007
    The highest I could get mine was around 16fps when using quarts with a bunch of animations. It depends on how complicated your game is going to be.
  8. jnic macrumors 6502a

    Oct 24, 2008
    Thirded. Up your NSTimer interval to 0.05 or so and see how it runs. The difference between 100 fps and 20 fps is only barely visible to the eye.

Share This Page