Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kmadhukishore

macrumors newbie
Original poster
Aug 28, 2009
1
0
Hi all,
I am planning to write a game based on Quartz 2D..
And following is the code for managing sprites,Of course constructor I will change accordingly for dynamic behavior by passing animation ID and manipulating the data:

Code:
view plaincopy to clipboardprint?
#import <UIKit/UIKit.h>  
  
class SpriteObject  
{  
public:  
    SpriteObject(UIView* parentView);  
private:  
    UIImageView* spriteView;  
};  
 
 
#import "SpriteObject.h"  
  
SpriteObject::SpriteObject(UIView* parentView)  
{  
    spriteView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0,100,100)];  
    NSArray* myImageArray = [[NSArray alloc] initWithObjects:  
                             [UIImage imageNamed:@"1.png"],  
                             [UIImage imageNamed:@"2.png"],  
                             [UIImage imageNamed:@"3.png"],  
                             [UIImage imageNamed:@"4.png"],  
                             nil];  
    spriteView.animationImages = myImageArray;  
    spriteView.animationDuration = 2.0;  
    spriteView.contentMode = UIViewContentModeCenter;  
    [parentView addSubview:spriteView];  
    [spriteView startAnimating];  
}

And in the main view controller class i am doing this:
Code:
view plaincopy to clipboardprint?
- (void)viewDidLoad {  
    [super viewDidLoad];  
       
     //Creating animation     
     new SpriteObject(self.view);  
  
     [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];  
}  
  
-(void) onTimer  
{  
        if(/*Some condition*/)  
        {  
           [spriteView stopAnimating];  
        }  
  
    //Sprite updating code....  
}
And I will
1)Create all Spites in the beginning of the game and I will add them to my View.
2)And each sprite is a UIImageViews etc.,.

Is this an efficient way??Or is there another nice way for managing sprites??

If I am not clear please tell me...

Thanks in advance....
Madhu.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.