With Cocos2d v2.0.0, a lot of changes were made and a lot of people are experiencing some scaling problems and other conflicts ...
This is even more true if they read and test out Ray Wenderlich's great book : Learning Cocos2d : The viking guy is to big, the background is not centered, the suffix system for images is not working, ...
So, how to proceed ?
Basically, everything is already told in the sample project when creating a new cocos2d v2 project. But, some of us need to get things pointed out.
Check out lines 68-71 from AppDelegate.m Here is what you need to remember :
You just need to call
CCSprite *mySprite = [CCSprite spriteWithFile:@"mySprite.png"];
Check out line 76 from AppDelegate.m
Just call the scene function from your class (using pushScene)
[director_ pushScene: [MyScene scene]];
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
BackgroundLayer *backgroundLayer = [BackgroundLayer node];
[scene addChild:backgroundLayer z:0];
GameplayLayer *gameplayLayer = [GameplayLayer node];
[scene addChild:gameplayLayer z:5];
return scene;
}
This is where scaling problems from v2 of cocos2d come from (but I do not know why).
Instead of calling -(id)init, call
-(void) onEnter{ //Do some sprite displaying with [self addChild:mySprite]; }
You can still call the -(id)init function for other things you need to load before displaying sprites.
You can find how to use sneakyinput with cocos2d v2 here : http://cl.ly/1J2D2z0f3o0r3h041o3o
Add this line to your layer (in the +(CCScene*) scene function or else where)
layer.isTouchEnabled = YES;
Then add this to the same .m
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray *touchArray=[touches allObjects];
if ([touchArray count] == 2)
{
NSLog(@"2");
}
else if([touchArray count]==1)
{
NSLog(@"1");
}
}
Finally, go to the AppDelegate.m and add this :
[[CCDirector sharedDirector].view setMultipleTouchEnabled:YES];
I would much appreciate if cocos2d v2 developers could help out and post stuff about how to use cocos2d v2 compared to v1.