sprite frame is not rotating in animation - ios

I want to rotate the third animation frame in my code below when it is run. I am doing this using an NSNotification when the frame is displayed to send a message. The animation plays without the third frame rotating. How can I solve this? I guess there could be 'simpler' ways to achieve this but I want to do it using NSNotifications.
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {
CCSpriteBatchNode* batchNode;
CCSpriteFrameCache* frameCache;
frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:#"cat-hd.plist"];
batchNode = [CCSpriteBatchNode batchNodeWithFile:#"cat-hd.pvr.ccz"];
[self addChild:batchNode];
CCSprite* wallbg = [CCSprite spriteWithSpriteFrameName:#"firstBg.png"];
wallbg.position= ccp(240.0, 160.0);
//wallbg.anchorPoint = ccp(0.5, 0.5);
[batchNode addChild:wallbg];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(rotateAnimationFrame:) name:CCAnimationFrameDisplayedNotification object:nil];
NSMutableArray* catAnimationArray = [[NSMutableArray alloc]init];
for(int i = 1; i < 7; i++) // i< number of frames in the plist File Name
{
CCLOG(#"item %d added", i);
[catAnimationArray addObject:
[frameCache spriteFrameByName:
[NSString stringWithFormat:#"blackCat%d.png", i]]]; }
CCSprite* catSprite = [CCSprite spriteWithSpriteFrameName: #"blackCat1.png"];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
catSprite.position = ccp(screenSize.width/2, screenSize.height/2);
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:catAnimationArray delay:0.6];
repeatMovement = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation :animation]];
[catSprite runAction:repeatMovement];
//CCAnimationFrame* thirdAnim = [CCSprite spriteWithSpriteFrame:#"catAnim3.png"];
CCRotateTo *rotateRight = [CCRotateBy actionWithDuration:0.3 angle:40.0];
rotateSprite = [catSprite runAction:rotateRight];
[batchNode addChild:catSprite];
NSDictionary* theInfo = [NSDictionary dictionaryWithObjectsAndKeys:rotateSprite,#"rotateSprite", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:self userInfo:theInfo];
CCAnimationFrame* thirdFrame = [animation.frames objectAtIndex:2];
thirdFrame.userInfo = theInfo;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(rotateAnimationFrame:) name:CCAnimationFrameDisplayedNotification object:nil];
}
return self;
}
-(void)rotateAnimationFrame:(NSNotification*)notification {
CCAction *rotateAction = [[notification userInfo] objectForKey:#"rotateSprite"];
}

Related

IOS - Collision Detection on Sprites using Cocos2d

In this game I have asteroids flying down from to top of screen, and a ship you can move freely, but I have added some collision detection and it does not seem to work in the update method when I call [self scheduleupdate];
// Import the interfaces
#import "HelloWorldLayer.h"
// Needed to obtain the Navigation Controller
#import "AppDelegate.h"
#pragma mark - HelloWorldLayer
// HelloWorldLayer implementation
#implementation HelloWorldLayer
// Helper class method that creates a Scene with the HelloWorldLayer as the only child.
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
if( (self=[super init]) ) {
self.isTouchEnabled = YES;
moveLeft = NO;
moveRight = NO;
speed = 3;
fireSpeed = 8;
fireArray = [[NSMutableArray alloc] init];
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite *bg = [[CCSprite alloc] initWithFile:#"space_bg.jpg"];
[bg setPosition:ccp(160, 240)];
CGSize imageSize = bg.contentSize;
bg.scaleX = winSize.width / imageSize.width;
bg.scaleY = winSize.height / imageSize.height;
bg.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:bg];
ship = [[CCSprite alloc] initWithFile:#"ship.png"];
[ship setPosition:ccp(100, 100)];
[self addChild:ship];
[self schedule:#selector(fireLoop:)];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:#selector(fireCreate)
userInfo:nil
repeats:YES];
asteroidArray = [[NSMutableArray alloc] init];
for(int i = 0; i < 100; ++i) {
CCSprite *asteroid = [[CCSprite alloc] initWithFile:#"asteroid1.png"];
[asteroidArray addObject:asteroid];
}
[self asteroidCreate];
[self scheduleUpdate];
}
return self;
}
CCSpriteBatchNode *spriteSheet;
NSMutableArray *asteroidAnimFrames;
- (float)randomValueBetween:(float)low andValue:(float)high {
return (((float) arc4random() / 0xFFFFFFFFu) * (high - low)) + low;
}
-(void)updtate:(ccTime)dt{
CGPoint shipPosition = [ship position];
for(int i = 0; i < asteroidArray.count; i++){
CCSprite *asteroid = [asteroidArray objectAtIndex:i];
if (CGRectIntersectsRect(ship.boundingBox, asteroid.boundingBox)) {
NSLog(#"hit");
}
}
}
- (void)countDownToCreateNextAsteroid {
int minTime = 1;
int maxTime = 10;
int randomTime = (arc4random() % (3));
id countdownDelay = [CCDelayTime actionWithDuration:randomTime];
id creationMethod = [CCCallFunc actionWithTarget:self selector:#selector(asteroidCreate)];
id countdownToCreateSeq = [CCSequence actions:countdownDelay, creationMethod, nil];
[self stopAllActions];
[self runAction:countdownToCreateSeq];
}
-(void)asteroidCreate {
CGSize winSize = [[CCDirector sharedDirector] winSize];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"asteroids.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"asteroids.png"];
asteroidAnimFrames = [NSMutableArray array];
for(int i=1; i <= 8; i++) {
[asteroidAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:#"asteroid%d.png", i]]];
}
CCAnimation *moveAsteroidAnim = [CCAnimation animationWithFrames:asteroidAnimFrames delay:0.1f];
CCSprite *asteroid = [CCSprite spriteWithSpriteFrameName:#"asteroid1.png"];
int x = arc4random() % 320;
int y = arc4random() % 480;
asteroid.position = ccp(x, 480);
CCAction *asteroidAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:moveAsteroidAnim restoreOriginalFrame:NO]];
[asteroidArray addObject:asteroid];
int q = arc4random() % 320;
int r = arc4random() % 10;
CCAction *moveAction = [CCMoveTo actionWithDuration:r position:ccp(q, -50)];
id asteroidRemove = [CCCallBlock actionWithBlock:^
{
[asteroid removeFromParentAndCleanup:YES];
[asteroidArray removeObject:asteroid];
}];
id asteroidSeq = [CCSequence actions:moveAction, asteroidRemove, nil];
[asteroid runAction:asteroidSeq];
[asteroid runAction:asteroidAction];
[spriteSheet addChild:asteroid];
[self addChild:spriteSheet];
[self countDownToCreateNextAsteroid];
}
-(void)fireLoop:(ccTime)fl {
if(fireArray.count > 0){
for(int i = 0; i < fireArray.count; i++){
CCSprite *tmpFire = [fireArray objectAtIndex:i];
if(tmpFire.position.y < 500){
[tmpFire setPosition:ccp([tmpFire position].x, [tmpFire position].y + fireSpeed)];
}else{
[fireArray removeObjectAtIndex:i];
}
}
} else {
}
}
-(void)fireCreate{
int shootPositionX = [ship position].x;
int shootPositionY = ([ship position].y) + 35;
CCSprite *fire;
fire = [[CCSprite alloc] initWithFile:#"fire.png"];
[fire setPosition:ccp(shootPositionX, shootPositionY)];
[fireArray addObject:fire];
[self addChild:fire];
[fire release];
}
-(void)gameLoop:(ccTime)dt {
int shipPositionX = 41/2;
if([ship position].x > shipPositionX){
[ship setPosition:ccp([ship position].x - speed, [ship position].y)];
}
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *t in touches){
CGPoint point = [self convertTouchToNodeSpace:t];
//if(point.x <= 160){
// moveRight = NO;
// moveLeft = YES;
//}else{
// moveRight =YES;
// moveLeft = NO;
//}
if(allowedToMove)
[ship setPosition:ccp(point.x, point.y + 76)];
}
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for(UITouch *t in touches){
CGPoint point = [self convertTouchToNodeSpace:t];
int shipX = [ship position].x;
int shipY = [ship position].y;
if (CGRectContainsPoint(CGRectMake (shipX - 20.5, shipY - 96, 50, 50), point))
{
allowedToMove = true;
}
}
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for(UITouch *t in touches){
CGPoint point = [self convertTouchToNodeSpace:t];
allowedToMove = false;
}
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
// don't forget to call "super dealloc"
[super dealloc];
}
#pragma mark GameKit delegate
-(void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] dismissModalViewControllerAnimated:YES];
}
#end

Objective-c: Using CCCallBlock causing error in Helper Class

I have a Helper Class that sets up animation but the code keeps failing when i call CCCallBlock.
Here is the Helper Class:
+(CCSpriteBatchNode*)setupAnimation:(NSString*)spriteNameWithoutPNG :(int)numberOfFrames :(CCSprite*)spriteObj :(int)startRandomX :(int)endRandomX :(int)endDuration{
CGSize winSize = [[CCDirector sharedDirector] winSize];
NSString *plist = [NSString stringWithFormat:#"%#.plist",spriteNameWithoutPNG];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plist];
NSString *spriteFileName = [NSString stringWithFormat:#"%#.png",spriteNameWithoutPNG];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:spriteFileName];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i=1; i <= numberOfFrames; i++){
NSString *frameName = [NSString stringWithFormat:#"%#%d.png",spriteNameWithoutPNG, i];
[animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
CCAnimation *moveAnim = [CCAnimation animationWithFrames:animFrames delay:0.1f];
NSString *spriteFrameName = [NSString stringWithFormat:#"%#1.png",spriteNameWithoutPNG];
spriteObj = [CCSprite spriteWithSpriteFrameName:spriteFrameName];
int x = arc4random() % startRandomX;
spriteObj.position = ccp(x, 480);
CCAction *actionFrames = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:moveAnim restoreOriginalFrame:NO]];
int q = arc4random() % endRandomX;
int r = arc4random() % endDuration;
CCAction *moveAction = [CCMoveTo actionWithDuration:r position:ccp(q, -50)];
id spriteObjRemove = [CCCallBlock actionWithBlock:^
{
[spriteObjRemove removeFromParentAndCleanup:YES];
//[asteroidArray removeObject:asteroid];
}];
id spriteSeq = [CCSequence actions:moveAction, spriteObjRemove, nil];
[spriteObj runAction:spriteSeq];
[spriteObj runAction:actionFrames];
[spriteSheet addChild:spriteObj];
return spriteSheet;
}
And this is how the code gets called in the parent:
-(void)asteroidCreate{
Asteroid *asteroid = [[Asteroid alloc] init:#"asteroid1.png"];
CCSpriteBatchNode *spritesheet = [Helper setupAnimation:#"asteroid" :8 :asteroid :320 :320 :10];
[self addChild:spriteSheet];
[self countDownToCreateNextAsteroid];
}
ERROR
Printing description of block:
<__NSStackBlock__: 0xbfffab90>
i doubt this is correct :
id spriteObjRemove = [CCCallBlock actionWithBlock:^
{
[spriteObjRemove removeFromParentAndCleanup:YES]; <=== using action instead of sprite
//[asteroidArray removeObject:asteroid];
}];
try
[spriteObj removeFromParentAndCleanup:YES];

multiple Animation Cocos2d 3.0

I have tried to run multiple animation 1.Player will stand on screen loading 2.Then he starts running when his frames finish 3.Player will stop and Go action performed
problem is go action is executed before run action finishes
can any one help me to perform this task like player run 0.6 secs then he stops running action and Go action execute and after 4 sec it stops
- (void)didLoadFromCCB
{
CGSize winSize = [[CCDirector sharedDirector] viewSize];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"cc_player.plist"];
NSMutableArray *runAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 12; i++)
{
[runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:#"cc_player/cc_player_run_pistol_%d.png", i]]];
}
NSMutableArray *goAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 11; i++)
{
[goAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:#"cc_player/cc_player_go_%d.png", i]]];
}
CCSprite *playerSprite = [CCSprite spriteWithImageNamed:#"cc_player/cc_player_idle_0.png"];
playerSprite.scale = 1.3;
playerSprite.position = CGPointMake(100, ( winSize.height / 2) - 60);
[self addChild:playerSprite z:3];
CCActionMoveTo *moveTo = [CCActionMoveTo actionWithDuration:8 position:CGPointMake(winSize.width+100 / 2, playerSprite.position.y)];
CCAnimation *runAnim = [CCAnimation animationWithSpriteFrames:runAnimFrames delay:0.06];
CCAnimation *goAnim = [CCAnimation animationWithSpriteFrames:goAnimFrames delay:0.06];
CCActionAnimate *runAnimationAction = [CCActionAnimate actionWithAnimation:runAnim];
CCActionAnimate *goAnimationAction = [CCActionAnimate actionWithAnimation:goAnim];
CCActionCallBlock *next=[CCActionCallBlock actionWithBlock:^
{
playerSprite.position = CGPointMake(playerSprite.position.x - 8, playerSprite.position.y + 6);
id goAction = [CCActionRepeat actionWithAction:goAnimationAction times:1];
CCActionCallBlock *nextStep=[CCActionCallBlock actionWithBlock:^
{
NSLog(#"***********not done");
// [playerSprite stopAllActions];
}];
CCActionSpawn *groupAction1 = [CCActionSpawn actionWithArray:#[goAction,nextStep]];
CCActionSequence *sequence2 = [CCActionSequence actionWithArray:#[groupAction1]];
// [playerSprite stopAllActions];
//CCActionSequence *goSequence = [CCActionSequence actions:moveTo,repeatingAnimation, nil];
[playerSprite runAction:sequence2];
}];
CCActionSpawn *groupAction = [CCActionSpawn actionWithArray:#[moveTo, next]];
CCActionSequence *sequence = [CCActionSequence actionWithArray:#[groupAction]];
[playerSprite runAction:sequence];
[playerSprite runAction:[CCActionRepeatForever actionWithAction:runAnimationAction]];
}
i have removed opticity line from code animation started showing now i have change sequance of my animation and its now working nice
(void)didLoadFromCCB
{
CGSize winSize = [[CCDirector sharedDirector] viewSize];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"cc_player.plist"];
NSMutableArray *runAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 12; i++)
{
[runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:#"cc_player/cc_player_run_pistol_%d.png", i]]];
}
NSMutableArray *goAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 11; i++)
{
[goAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:#"cc_player/cc_player_go_%d.png", i]]];
}
CCSprite *playerSprite = [CCSprite spriteWithImageNamed:#"cc_player/cc_player_idle_0.png"];
playerSprite.scale = 1.3;
playerSprite.position = CGPointMake(100, ( winSize.height / 2) - 60);
[self addChild:playerSprite z:3];
CCActionMoveTo *moveTo = [CCActionMoveTo actionWithDuration:3 position:CGPointMake(300, playerSprite.position.y)];
CCAnimation *runAnim = [CCAnimation animationWithSpriteFrames:runAnimFrames delay:0.06];
CCAnimation *goAnim = [CCAnimation animationWithSpriteFrames:goAnimFrames delay:0.06];
CCActionAnimate *runAnimationAction = [CCActionAnimate actionWithAnimation:runAnim];
CCActionAnimate *goAnimationAction = [CCActionAnimate actionWithAnimation:goAnim];
CCActionCallBlock *next=[CCActionCallBlock actionWithBlock:^
{
playerSprite.position = CGPointMake(playerSprite.position.x - 8, playerSprite.position.y + 6);
id goAction = [CCActionRepeat actionWithAction:goAnimationAction times:1];
CCActionCallBlock *nextStep=[CCActionCallBlock actionWithBlock:^
{
// [playerSprite stopAllActions];
}];
CCActionSpawn *groupAction1 = [CCActionSpawn actionWithArray:#[goAction,nextStep]];
CCActionSequence *sequence2 = [CCActionSequence actionWithArray:#[groupAction1]];
// [playerSprite stopAllActions];
//CCActionSequence *goSequence = [CCActionSequence actions:moveTo,repeatingAnimation, nil];
[playerSprite runAction:sequence2];
}];
[playerSprite runAction:[CCActionRepeatForever actionWithAction:runAnimationAction]];
CCActionSpawn *groupAction = [CCActionSpawn actionWithArray:#[moveTo,runAnimationAction]];
CCActionSequence *sequence = [CCActionSequence actionWithArray:#[groupAction,next]];
[playerSprite runAction:sequence];
}

Multiple UITableView with independent dataSource

[EDIT]
Ok I found the problem, I was just calling the bad connection request of my web service. So downloading a blog would erase the articles list content. Time for a break :p
#
I'm upgrading an old app which is a simple RSS reader with a list of articles and a list of blogs. Each of these is a UITableView with its own UITableViewController.
Both of them retrieve data from a JSON file on my server.
At the end of the JSON parsing I update the dataSources and then call the reloadData method on both tableviews. The problem is that the articles list is filled with the blogs and the blog list isn't filled at all.
If I don't call reloadData on the blog tableview, the article one is filled correctly and works well. As seen on an other post I've tried with the tableview.tag identifier but it doesn't work.
Note: I'm not using IB.
Here is the code for the BlogTableViewController:
#implementation BlogsTVC
#synthesize dataSourceForBlogs;
#synthesize blogRec;
- (id)initWithStyle:(UITableViewStyle)style
{
if ((self = [super initWithStyle:style])) {
self.title = #"Blogs";
self.tableView.tag = 2;
self.tableView.delegate = self;
dataSourceForBlogs = [[NSMutableArray alloc] init];
// Register to notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callback_blogs:) name:#"blogs" object:nil ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(connection_error:) name:#"connection_error" object:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self refreshBlogs];
}
-(void)callback_blogs:(NSNotification *)notification
{
if([self.dataSourceForBlogs count] > 0)
{
NSInteger i, count = [self.dataSourceForBlogs count];
for(i=0; i < count; i++)
{
[[self.dataSourceForBlogs objectAtIndex:i] release];
}
[self.dataSourceForBlogs removeAllObjects];
}
//remplissage
NSArray *receivedDatas = [[notification userInfo] objectForKey:#"data"];
NSUInteger i, count = [receivedDatas count];
for(i=0; i<count; i++)
{
self.blogRec = [[BlogRecord alloc] init];
self.blogRec.blog_id_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"id"];
self.blogRec.blog_auteur = [[receivedDatas objectAtIndex:i]objectForKey:#"auteur"];
self.blogRec.blog_url = [[receivedDatas objectAtIndex:i]objectForKey:#"url"];
self.blogRec.blog_date = [[receivedDatas objectAtIndex:i] objectForKey:#"date"];
self.blogRec.blog_nb_pub = [[receivedDatas objectAtIndex:i] objectForKey:#"nb_publication"];
self.blogRec.blog_url_image = [[receivedDatas objectAtIndex:i] objectForKey:#"theme"];
[self.dataSourceForBlogs addObject:self.blogRec];
self.blogRec = nil;
}
[self.tableView reloadData];
}
Here is the code for the Articles:
#implementation ActualiteTVC
#synthesize dataSource;
#synthesize artRec;
#pragma mark -
#pragma mark Initialization
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if ((self = [super initWithStyle:style])) {
// Titles
self.title = #"Actualités";
self.tableView.tag = 1;
// Register to notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callback_general:) name:#"general" object:nil ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(connection_error:) name:#"connection_error" object:nil];
self.dataSource = [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
[self refreshNews];
}
-(void)callback_general: (NSNotification *) notification
{
if ([self.dataSource count] > 0) {
NSUInteger i, count = [self.dataSource count];
for (i = 0; i < count; i++) {
[[self.dataSource objectAtIndex:i] release];
}
[self.dataSource removeAllObjects];
}
NSArray *receivedDatas = [[notification userInfo] objectForKey:#"data"];
NSUInteger i, count = [receivedDatas count];
for (i = 0; i < count; i++) {
self.artRec = [[ArticleRecord alloc] init];
self.artRec.art_id = [[receivedDatas objectAtIndex:i] objectForKey:#"id"];
self.artRec.art_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"auteur"];
self.artRec.art_categorie = [[receivedDatas objectAtIndex:i] objectForKey:#"categorie"];
self.artRec.art_date = [[receivedDatas objectAtIndex:i] objectForKey:#"date"];
//self.artRec.art_texte = [[receivedDatas objectAtIndex:i] objectForKey:#"texte"];
self.artRec.art_titre = [[receivedDatas objectAtIndex:i] objectForKey:#"titre"];
self.artRec.art_url_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"url_auteur"];
self.artRec.art_url = [[receivedDatas objectAtIndex:i] objectForKey:#"url"];
self.artRec.art_url_img = [[receivedDatas objectAtIndex:i] objectForKey:#"image"];
[self.dataSource addObject:self.artRec];
self.artRec = nil;
}
[self.tableView reloadData];
}
Finally here is how I add these TableViews in the TabBar:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 0
//articles
ActualiteTVC *actualiteTVC = [[ActualiteTVC alloc] init];
UINavigationController *actualiteNC = [[UINavigationController alloc] initWithRootViewController:actualiteTVC];
[actualiteTVC release];
actualiteNC.tabBarItem.title = #"Actualités";
actualiteNC.tabBarItem.image = [UIImage imageNamed:#"08-chat.png"];
[actualiteNC.navigationBar setBarStyle:UIBarStyleBlack];
//1
//blogs
BlogsTVC *blogsTVC = [[BlogsTVC alloc] init];
UINavigationController *blogsNC = [[UINavigationController alloc] initWithRootViewController:blogsTVC];
[blogsTVC release];
blogsNC.tabBarItem.title = #"Blogs";
blogsNC.tabBarItem.image = [UIImage imageNamed:#"balance.png"];
[blogsNC.navigationBar setBarStyle:UIBarStyleBlack];
// myTabBarController
myTabBarController = [[UITabBarController alloc] init];
[myTabBarController setViewControllers:[NSArray arrayWithObjects:actualiteNC, blogsNC, nil]];
[actualiteNC release];
[blogsNC release];
/*
//fullscreen
CGRect frame = [[UIScreen mainScreen] applicationFrame];
frame.origin.x = 0;
frame.origin.y = 25;
//[baseViewCtrl.view setFrame:frame];
[myTabBarController.view setFrame:frame];
*/
/*
// window
//[window addSubview:myTabBarController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleRemoveLoading:) name:#"removeLoading" object:nil];
loading = [[LoadingVC alloc] init];
[window addSubview:loading.view];
*/
[window addSubview:baseViewCtrl.view];
[window makeKeyAndVisible];
return YES;
}

One CCAction to few sprites - need to properly remove them all

I add one sprite per body and run animation, but when I try to remove this sprite after reloading scene(calling afterLoadProcessing once again) - removes the only first with animation. I'm new to iOS & Cococs2D programming, please help me with advice.
Here is my code:
-(void)afterLoadProcessing:(b2dJson*)json
{
[super afterLoadProcessing:json];
[self removeChild:enemysprite cleanup:YES];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"player_enemy.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"player_enemy.png"];
[self addChild:spriteSheet];
NSMutableArray *enemyGusenitsaAnimFrames = [NSMutableArray array];
for (int i = 31; i <=36; ++i) {
[enemyGusenitsaAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"%d.png",i]]];
}
CCAnimation *gusenitsaMovAnim = [CCAnimation animationWithSpriteFrames:enemyGusenitsaAnimFrames delay:0.1f];
_enemyGusenitsaMovement = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:gusenitsaMovAnim]];
_enemyGusenitsaMovement.tag = 109;
std::vector<b2Body*> enemySprites;
json->getBodiesByName("enemy", enemySprites);
for (int i = 0; i < enemySprites.size(); i++) {
b2Body *bod = enemySprites[i];
enemysprite = [[CCSprite alloc] init];
[enemysprite stopAllActions];
enemysprite.scale = 0.04;
[self addChild:enemysprite z:50];
bod->SetUserData(enemysprite);
[[enemysprite runAction:[_enemyGusenitsaMovement copy]] autorelease];
}
}
Instead of use [self removeChild:enemysprite cleanup:YES];, you can remove all children
[self removeAllChildrenWithCleanup:YES];
Or loop all bodies and remove it :
for (int i = 0; i < enemySprites.size(); i++) {
b2Body *bod = enemySprites[i];
CCSprite *sprite = (CCSprite *)bod->GetUserData();
[self removeChild:sprite];
}

Resources