For sure i will let you know when i move there ;) first i have to learn Obj-C and cocos2d jeje
Upcoming book - Cocos2d for iPhone 0.99 Beginner's Guide
(59 posts) (21 voices)-
Posted 1 year ago #
-
Hi,
Reading through the timer example in the book on page 28, you use the schedule:@selector method of scheduling an update to your node. However, when I refer to the cocos wiki, it says to use scheduleUpdate over scheduleSelector for performance reasons : http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update#scheduleupdate
Would this be a better approach to take in this case?
Thanks,
StevePosted 1 year ago # -
Yes it would, but as the chapter was written a while back the scheduleUpdate method didn't exist :)
Posted 1 year ago # -
I've had issues getting the first example to work with the 0.99.5 application template, as my game kept crashing with memory access errors. I ran through the example again using the default 0.99.4 application template and didn't encounter any issues.
This may just be attributed to my own lack of Objective-C knowledge, or something I've missed in the listings, so let me know if it's me being a numpty, by all means!
Posted 1 year ago # -
Just purchased your book (looks like a good one).
No offense, but I wish you had gone with iBooks -- Packt is kind of frustrating. I couldn't get to my download without clicking through what looked like a "credit card protection" scam page (man, I really hope they didn't sign me up for something I won't be able to cancel). Second, their product page said the book was available in PDF and ePub (I really prefer ePub) but the download page was only PDF.
Anyway, sorry for the gripes; the book looks good and I think it will definitely help me with my project. Good luck with sales!
Posted 1 year ago # -
@CausticMango Thanks! Yes, i have been told their payment system is a crap... It is really a shame...
I have had no problems in the past buying a book from them, but a lot of people told me they were having problems.
Anyways, i hope you enjoy the book!Posted 1 year ago # -
Sorry for being such a noob, I have read your book and I have learned a lot of things so far. I wonder a couple of things though, I can't get the Colored Stones game to use -hd spritesheet too when I have enabled and preloaded it in the Delegate.
I only get one sheet to work, the other just show half of each stone on the iphone 4. Should I add all sprites to the same sheet and have the -hd prefix on the Retina sprites or should I have two separate spritesheets?
I have followed the code and the instructions from the book.
My problem is in the -(CGRect)setStoneColor:(int)stoneT method, it worked with -hd sprites before when I loaded individual sprites as it is done early in the book. I'm very greatful for any help I could get to show me how to use both spritesheets in that method.
David#import "Stone.h" @implementation Stone @synthesize state,mySprite,theGame,stoneType,curVGroup,curHGroup,disappearing,initDir,isSelected; -(id) initWithGame:(GameLayer*) game { if ((self = [super init])) { self.theGame = game; [game addChild:self]; //[self->mySprite setVisible:NO]; self.state = kStateUngrabbed; self.isSelected = NO; } return (self); } -(void)placeInGrid:(CGPoint)place pt:(int)pt pl:(int)pl { int sType = arc4random() % 4; if(sType == pt || sType == pl) { [self placeInGrid:place pt:pt pl:pl]; return; }else{ //CGRect colorRect =[self setStoneColor:sType]; // Code from the book (Normal Res spritesheet) CCSpriteSheet * s = (CCSpriteSheet *)[theGame getChildByTag:K_SSheet]; mySprite = [CCSprite spriteWithSpriteSheet:s rect:[self setStoneColor:sType]]; [s addChild:mySprite z:1]; // My code for -hd (hiRes Res spritesheet) CCSpriteSheet * hd = (CCSpriteSheet *)[theGame getChildByTag:K_HDSheet]; mySprite = [CCSprite spriteWithSpriteSheet:s rect:[self setStoneColor:sType]]; [hd addChild:mySprite z:1]; [self setAnimation]; self.stoneType =sType; [self.mySprite setPosition:place]; } } -(void)setAnimation { [self.mySprite stopAllActions]; CCAnimation *animation; switch (self.stoneType) { case 0: break; case 1: animation = [CCAnimation animationWithName:@"fBlue" delay:0.1f frames:theGame.blueFrames]; [self.mySprite runAction:[CCRepeatForever actionWithAction: [CCSequence actions:[CCDelayTime actionWithDuration:arc4random()%5],[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO],nil] ]]; break; case 2: break; case 3: break; } } -(CGRect)setStoneColor:(int)stoneT { self.stoneType = stoneT; CGRect color; switch (self.stoneType) { case 0: color = CGRectMake(68,2,32,32); break; case 1: color =CGRectMake(132,2,32,32); break; case 2: color = CGRectMake(2,2,32,32); break; case 3: color = CGRectMake(100,2,32,32); break; } return color; } - (CGRect)rect { //CGSize s = [self.texture contentSize]; CGRect c = CGRectMake(mySprite.position.x-(self.mySprite.textureRect.size.width/2) * self.mySprite.scaleX ,mySprite.position.y-(self.mySprite.textureRect.size.height/2)* self.mySprite.scaleY,self.mySprite.textureRect.size.width* self.mySprite.scaleX,self.mySprite.textureRect.size.height * self.mySprite.scaleY); return c; } - (void)onEnter { [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; [super onEnter]; } - (void)onExit { [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; [super onExit]; } - (BOOL)containsTouchLocation:(UITouch *)touch { return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]); } - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if (state != kStateUngrabbed) return NO; if ( ![self containsTouchLocation:touch]) return NO; if (theGame.disallowTouch) return NO; CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; self.initDir = location; self.isSelected = YES; state = kStateGrabbed; return YES; } - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { NSAssert(state == kStateGrabbed, @"Paddle - Unexpected state!"); CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; CGPoint aux = ccpNormalize(ccp(location.x-initDir.x,location.y-initDir.y)); int dir =0; //NSLog(@"%f,%f",fabsl(aux.x),fabsl(aux.y)); if(fabsl(aux.x) >= fabsl(aux.y)) { if(aux.x>=0) dir=1; else dir=2; }else{ if(aux.y>=0) dir=3; else dir=4; } [theGame swapStones:self dir:dir]; [self.mySprite setOpacity:255]; state = kStateUngrabbed; self.isSelected = NO; } -(void)draw { if(isSelected) { [self.mySprite setOpacity:100]; glColor4ub(255, 0, 0, 100); glPointSize(30); ccDrawPoint( self.mySprite.position); } } @endPosted 1 year ago # -
@pabloruiz55
Do you have a support site or forum for the book?Posted 1 year ago # -
Can someone please help me with my previous post, I just finished a tutorial by Ray W but he does it differently. How should I write so the game uses -hd sprites also in the switch statement?
Posted 1 year ago # -
I'm up to page 133 and am trying to compile the project, but keep getting errors when compiling on Tutorial.h.
If I don't declare the GameLayer class using : @class GameLayer , I get 'Expected specifier-qualifier-list before' errors on theGame and state properties.
If I do, I still get an error on the state property.
This isn't necessary in the project provided in the source code for Chapter 4 - can anyone help me identify where I've gone wrong?
Thanks!
Posted 1 year ago # -
@cell-gfx
I had that problem too so I just added the @class GameLayer.I've been learning development for a year and I found this book the easiest to grasp of all the different devbooks I have bought. Currently I am trying to enhance the Colored Stones Game with;
1, HiRes artwork.
2, Adding an animation to the Stones when they are touched/moved/released (scale up/down) sort of make the touched Stone dragged over the other while swapping places.
3, Remove the ability to swap Stones when there is no match, (at the moment you can swap and get time penalty) change this so the stone bounce back when you try to swap.
4, Save Score.
5, Add Combos, Bonuses, Particle FX when matching 5 or more and add a Label "Awesome", "JackPot!" etc when that happens.
6, Add GameCenter or OpenFeint
7, Pause, Resume, Restart option.
8, Make it so the player can listen to music from ipod as an option from having Background music looping.
I have added sounds when swapping, Stones falling to their place, when matching 4 or more and added a really annoying background Loop but I think I should have some sort of gameManager to handle states, music, score, preferences etc..
I have also made a menu but it was too annoying when testing the game to go thru the menu so I disabled that and loaded directly to the GameScene.
At the moment I am stuck with the HiRes part in the -(CGRect)setStoneColor:(int)stoneT method, I'm not sure how to implement the -hd stones. I have 2 spritesheets (SD and HD) but I have also tried to have all sprites in one sheet, what would be the best thing to do?
Should I use two spritesheets (spritesheet.png, spritesheet-hd.png) or one large sheet with all sprites?
Note: All HD sprites have the -hd prefix.Inside the Switch statement, should I add an if( ) inside each case or how should I go about with this?
Anyone have any suggestions?
Posted 1 year ago # -
@David: If you upgrade to 0.99.5 you don't have to use any conditionals. Just create the highres spritesheet using your favorite texture packing tool and name it -hd (or whatever you like, this can be changed in the cocos2d config file). Then enable retina display and you should be ok.
Check this guide for precise instructions ans information:http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2d
I am glad you find the book useful and i would love to see your version of the game in the store!, beating Bejeweled maybe? ;)
Posted 1 year ago # -
Posted 1 year ago #
-
Hi,
I'm working through the example in Chapter 5, up to page 156, using a 0.99.5 template and am having a problem.
Whenever I run the game in the simulator, it rotates to landscape mode. I have ensured that the simulator is running in portrait and have also set the GAME_AUTOROTATION global in GameConfig.h to kGameAutorotationNone (which should set the simulator to portrait), but it always switches.
Can anyone help please?
Thanks!
Posted 1 year ago # -
Resolved my issue by following the comments here : http://www.cocos2d-iphone.org/forum/topic/9744
Posted 1 year ago # -
pabloruiz55 : My school wanted to introduce developing on Mac platform for mobile platforms (iPhone) and we use cocos2d to show that to the students, as it's perfect for the limited time (4 weeks) we have on this.
As I already knew the book's content, I knew it was perfect ,they're buying about 20 and it'll be the guide for the class heh.
I guess it could be fun for you to know that your book is used in college classes heh.
The students will create a simple game each, with only basic C knowledge, a Mac and this book.
Posted 1 year ago # -
Hi,
I've followed the book through to the end of Chapter 5 and there are a couple of issues I'm encountering with the game.
First, if I pause the game and try to unpause it tapping anywhere along the HUD layer, the game crashes. This behaviour is also present in the demo project for Chapter 5 in the source code.
Secondly, I don't know if it's related to my use of the 0.99.5 template for the app, but whenever I unpause the game after locking the screen (as opposed to pausing it manually), the accelerometer stops responding to movements.
Can you advise as to what might be causing these issues?
Thanks!
Posted 1 year ago # -
@cell-gfx: I have just spotted the problem, what happens is that both HudLayer's and PauseLayer's ccTouchesBegan methods are being called at the same time is touching up there.
To solve that you can:1- Move the PauseLayer's ccTouchesBegan code to ccTouchedEnded
2- add a new variable to PauseLayer: bool beganTouching
3- set that variable to NO in the init method.
4-`- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
beganTouching = YES;
}`
5-Finally in GameLayer's class, the pauseGame should look like this:
-(void)pauseGame { if(![AerialGunAppDelegate get].paused) { ccColor4B c = {100,100,0,100}; PauseLayer * p = [[[PauseLayer alloc]initWithColor:c]autorelease]; [self.parent addChild:p z:10]; [self onExit]; } }Another way to solve this is to change the hudlayer so you can pause the game using a CCMenu, that would be cleaner and avoid this issue.
Regarding number 2, i would have to check it, but i don't have my iDevice with me now...
Thanks for spotting these issues and for all the support.
Posted 1 year ago # -
I've got another problem with the particle example in Chapter 7 as well; for some reason, I can't get the game to detect when there are multiple touches on the screen. I've added an NSLog that writes [touches count] out to the debugger, but whenever ccTouchesBegan is called, it always returns 1 as the count. This is also the case if I tap with two or more fingers or hold one down and tap with another.
** Don't worry - it appears to be a wider ranging issue than the code in the game!
http://www.cocos2d-iphone.org/forum/topic/12882Posted 1 year ago # -
Hello all,
Im new to all the iphone and cocos2d development. Ive been reading the book, and doing the 2ยบ chapter and im a bit stuck in the stone swapping.
every time i run the application, it doesnt recognize my swipe:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { NSLog(@"Began"); if (state != kStateUngrabbed) return NO; if ( ![self containsTouchLocation:touch]) return NO; if (theGame.disallowTouch) return NO; NSLog(@"Here"); CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; self.initDir = location; state = kStateGrabbed; return YES; }Ive puted 2 NSLogs to see where he goes, and the output is this:
2011-01-28 13:58:57.449 Coloured Stones[870:207] Began
2011-01-28 13:58:57.461 Coloured Stones[870:207] Began
2011-01-28 13:58:57.469 Coloured Stones[870:207] Began
2011-01-28 13:58:57.481 Coloured Stones[870:207] Began
2011-01-28 13:58:57.491 Coloured Stones[870:207] Began
2011-01-28 13:58:57.496 Coloured Stones[870:207] Began
2011-01-28 13:58:57.500 Coloured Stones[870:207] Began
2011-01-28 13:58:57.504 Coloured Stones[870:207] Began
2011-01-28 13:58:57.528 Coloured Stones[870:207] Began
2011-01-28 13:58:57.534 Coloured Stones[870:207] Began
2011-01-28 13:58:57.550 Coloured Stones[870:207] Began
2011-01-28 13:58:57.553 Coloured Stones[870:207] Began
2011-01-28 13:58:57.570 Coloured Stones[870:207] Began
2011-01-28 13:58:57.584 Coloured Stones[870:207] Began
2011-01-28 13:58:57.590 Coloured Stones[870:207] Began
2011-01-28 13:58:57.596 Coloured Stones[870:207] Began
2011-01-28 13:58:57.602 Coloured Stones[870:207] Began
2011-01-28 13:58:57.614 Coloured Stones[870:207] Began
2011-01-28 13:58:57.622 Coloured Stones[870:207] Began
2011-01-28 13:58:57.630 Coloured Stones[870:207] Began
2011-01-28 13:58:57.638 Coloured Stones[870:207] Began
2011-01-28 13:58:57.649 Coloured Stones[870:207] Began
2011-01-28 13:58:57.657 Coloured Stones[870:207] Began
2011-01-28 13:58:57.671 Coloured Stones[870:207] Began
2011-01-28 13:58:57.693 Coloured Stones[870:207] Began
2011-01-28 13:58:57.697 Coloured Stones[870:207] Began
2011-01-28 13:58:57.704 Coloured Stones[870:207] Began
2011-01-28 13:58:57.713 Coloured Stones[870:207] Began
2011-01-28 13:58:57.717 Coloured Stones[870:207] Began
2011-01-28 13:58:57.723 Coloured Stones[870:207] Began
2011-01-28 13:58:57.751 Coloured Stones[870:207] Began
2011-01-28 13:58:57.767 Coloured Stones[870:207] Began
2011-01-28 13:58:57.772 Coloured Stones[870:207] Began
2011-01-28 13:58:57.779 Coloured Stones[870:207] Began
2011-01-28 13:58:57.786 Coloured Stones[870:207] Began
2011-01-28 13:58:57.795 Coloured Stones[870:207] Began
2011-01-28 13:58:57.805 Coloured Stones[870:207] Began
2011-01-28 13:58:57.811 Coloured Stones[870:207] Began
2011-01-28 13:58:57.824 Coloured Stones[870:207] Began
2011-01-28 13:58:57.833 Coloured Stones[870:207] Began
2011-01-28 13:58:57.837 Coloured Stones[870:207] Began
2011-01-28 13:58:57.853 Coloured Stones[870:207] Began
2011-01-28 13:58:57.861 Coloured Stones[870:207] Began
2011-01-28 13:58:57.865 Coloured Stones[870:207] Began
2011-01-28 13:58:57.871 Coloured Stones[870:207] Began
2011-01-28 13:58:57.877 Coloured Stones[870:207] Began
2011-01-28 13:58:57.895 Coloured Stones[870:207] Began
2011-01-28 13:58:57.904 Coloured Stones[870:207] Began
2011-01-28 13:58:57.909 Coloured Stones[870:207] Began
2011-01-28 13:58:57.915 Coloured Stones[870:207] Began
2011-01-28 13:58:57.923 Coloured Stones[870:207] Began
2011-01-28 13:58:57.936 Coloured Stones[870:207] Began
2011-01-28 13:58:57.953 Coloured Stones[870:207] Began
2011-01-28 13:58:57.960 Coloured Stones[870:207] Began
2011-01-28 13:58:57.964 Coloured Stones[870:207] Began
2011-01-28 13:58:57.972 Coloured Stones[870:207] Begancan someone help me please
Posted 1 year ago # -
PS: im stuck on page 60-61
Posted 1 year ago # -
There seems to be a lot warnings in the source code, I'm on chapter 9 at the moment and I can't get around to getting rid of the warning message
Method -initWithGame:" not found(return type defaults to "id")
This is found in the GameScene.m file and others related.
Is there a way to update the code to get rid of the warnings, so far the count is at 37 warnings???
Posted 1 year ago # -
what's the license on all the code?
Posted 1 year ago # -
I'm getting an error thrown at me from the GameScene class in the pauseGame. This is the line that's giving me fits:
PauseLayer * p = [[[PauseLayer alloc]initWithColor:c]autorelease];I'm getting an "Incompatible type for argument 1 of 'initWithColor:'" error. I'm using the newest Xcode beta and cocos2d 0.99.5. Have any of you had this problem as well? If so, how did you go about fixing it?
Posted 11 months ago # -
I tried changing the
initWithColortoCCLayerColor, but that throws several other errors.Posted 11 months ago # -
Granted there is some challenging mistakes in the book and you can tell is has been rushed, but these these minor hiccups only help you problem solve for yourself I have found.
pabloruiz55: Personally you have done a fantastic job with the book and provide polish modern games, techniques and in great best practices. I am a big fan of your book.
Thank you for sharing what would have taken me a lifetime to learn.
Jean-Noel
Posted 11 months ago #
Reply
You must log in to post.