Cocos2D 2.0 screenshots on iOS 6

I am not sure what the GitHub version does but this code will take a screenshot and I just tested it on iOS 6 and it works fine. +(UIImage*) screenshotWithStartNode:(CCNode*)startNode { [CCDirector sharedDirector].nextDeltaTimeZero = YES; CGSize winSize = [CCDirector sharedDirector].winSize; CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height]; [rtx begin]; [startNode visit]; [rtx end]; return [rtx getUIImage]; … Read more

how can I use animation in cocos2d?

It’s quite simple in Cocos2D: [sprite runAction:[RotateBy actionWithDuration:dur angle:360]]; to make one turn or id action = [RepeatForever actionWithAction: [RotateBy actionWithDuration:dur angle:360]]; [sprite runAction:action]; and [sprite stopAction:action]; if you need to rotate continuously. Don’t forget to make sure that sprite transformAnchor is set to center of the image. And I guess next question should arise … Read more

Detect when UIGestureRecognizer is up, down, left and right Cocos2d

Apparently each UISwipeGestureRecognizer can only detect the swipe in the given direction. Even though the direction flags could be OR’ed together the UISwipeGestureRecognizer ignores the additional flags. The solution is to add one UISwipeGestureRecognizer for each direction you want the swipe gesture to be recognized, and set each recognizer’s direction accordingly to either up, down, … Read more

Cocos2D 2.0 – Zillions of OpenGL errors

OpenGL error 0x506 = GL_INVALID_FRAMEBUFFER_OPERATION Main difference between Cocos2D 2.0 and Cocos2D 1.0 is OpenGLES version. Cocos2D 2.0 uses OpenGLES 2.0 and Cocos2D 1.0 uses OpenGLES 1.0. I guess you may used API that is not found in OpenGLES2.0 that found in OpenGLES 1.0 Example:GLBegin(), GLLineWidth() etc Use this draw function: -(void) draw { [super … Read more

Moving a Stick figure, anchorpoints, animation, or something else…?

My general advice: never, ever modify the default anchorPoint (0.5f, 0.5f) unless you have a really good understanding of what it does and how it helps you accomplish things. In all other cases, modify the position property. Especially if you do bounding box or radius based collision detection, modifying the anchor point is counter-productive. Let’s … Read more

Objective C – get the following day from today (tomorrow)

Using NSDateComponents you can extract day/month/year components from the date representing today, ignoring the hour/minutes/seconds components, add one day, and rebuild a date corresponding to tomorrow. So imagine you want to add exactly one day to the current date (including keeping hours/minutes/seconds information the same as the “now” date), you could add a timeInterval of … Read more

How Make the players waiting [closed]

Create a date object when the player loses NSDate *stopTime = [NSDate dateWithTimeIntervalSinceNow:0]; and store that date in NSUserDefaults. To check if the user has waited long enough, read the date from NSUserDefaults, and compute the delta between the stop time and the current time. For example, if the user needs to wait 15 minutes, … Read more