objective-c,cocos2d-iphoneRelated issues-Collection of common programming errors


  • Brock Woolf
    objective-c cocoa cocoa-touch nsstring
    I have an NSString like so:@”200hello”or @”0 something”What I would like to be able to do is take the first occuring number in the NSString and convert it into an int. So that @”200hello” would become int = 200.and @”0 something” would become int = 0.

  • Bartosz Ciechanowski
    objective-c lambda objective-c-blocks continuations structured-programming
    When using methods which return blocks they can be very convenient. However, when you have to string a few of them together it gets messy really quicklyfor instance, you have to call 4 URLs in succession:[remoteAPIWithURL:url1 success:^(int status){[remoteAPIWithURL:url2 success:^(int status){[remoteAPIWithURL:url3 success:^(int status){[remoteAPIWithURL:url2 success:^(int status){//succes!!!}];}];}]; }];So for every iteration I go one level deeper, and I don’t even handle errors in the nested

  • Rakhe Kara
    ios iphone objective-c cocoa-touch
    Actually this crash is not reproducing every time, even not frequently but we got this crash in our production app. I am not sure where is the problem. It is telling crash is happening in thread 4 in Environments class line number 38.Code:NSBundle* bundle = [NSBundle mainBundle];NSString* envsPListPath = [bundle pathForResource:@”Environment” ofType:@”plist”];Line 38: NSDictionary *environments = [[NSDictionary alloc] initWithContentsOfFile:envsPListPath];But according to exception type:00000020

  • Musterknabe
    ios objective-c
    I have the following problem. I have a Model, called User. When the user now logins with Facebook, my app checks if the user exists already in the database. To not freeze the UI (since I’m coming from Android) I thought to use NSURLConnection sendAsynchronousRequest. What worked at first was the following:My User Model had a method to do the whole task of the AsynchronousRequest and then when finished would set a variable to loading. Then other classes, could simply check with while ( !user.loa

  • Josh Bradley
    objective-c sockets bsd-sockets
    Ok, I have a problem with building a socket using Objective-C. If you’ll take a look at my code below, through help with example code and other sources, I was able to build a complete socket I believe. The problem is that when I compile it, it builds fine (no syntax problems), but there are no sockets being created. As you’ll notice I’ve commented out a lot of things in Server2.m and have isolated the problem to the very beginning when I create the struct for the listeningSocket. By the way, if

  • Todd Ditchendorf
    objective-c xcode frameworks compiler-errors parsekit
    I am trying to add the Parsekit framework to my OSX Xcode project. I’ve never added a 3rd party framework before and I can’t get it to work right.I dragged the included Xcode project into my ‘Groups & Files’ pane and chose to Add it to my project. I then dragged Parsekit.framework underneath the Link Binary With Libraries heading. Then I double-clicked my target app and added Parsekit as a Direct Dependency. I also added libicucore.dylib as a Linked Library (as it says to do this on their si

  • zioolek
    objective-c cocoa nsimage pgm
    Hi everyone! It is my first post here.I am quite new in objective-c so maybe my question is not so hard but It is a problem for me. I’ve searched the web and didn’t find any useful hints for me… I am writing a program in Objective-c in Xcode. I need to read and display a pgm file (P5 with two bytes per pixel). To do that i’m trying to subclass NSImageRep but I don’t know how to create a proper bitmap for this file and how to draw it. Below is my code so far:header:@interface CTPWTPGMImageRep :

  • Oliver
    iphone objective-c uiscrollview
    How can I force a UIScrollView in which paging and scrolling are on to only move vertically or horizontally at a given moment?My understanding is that the directionalLockEnabled property should achieve this, but a diagonal swipe still causes the view to scroll diagonally instead of restricting motion to a single axis.Edit: to be clearer, I’d like to allow the user to scroll horizontally OR vertically, but not both simultaneously.

  • Elwisz
    objective-c osx cocoa nsdocument autosave
    I have a NSDocument based OS X app which instead of creating new documents with a blank page shows a panel to the user to chose a template from, like for example Apple’s Pages.app does.I made this by manually creating a new NSDocument instance when the user starts a new document and immediately setting a property on it to reflect which template the user has chosen for it:MyNSDocumentSubclass *newDoc = [sharedDocumentController makeUntitledDocumentOfType:fileType error:&err]; [newDoc setTempl

  • Kanwar Singh
    iphone objective-c json ios6 afnetworking
    I have webservice in java. and i am posting JSON by AFnetworking but its not working when i user below codeNSURL *url = [NSURL URLWithString:@”http://localhost8080/webservice/usersprofile/”]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; // don’t forget to set parameterEncoding! httpClient.parameterEncoding = AFJSONParameterEncoding;NSDictionary *params = @{@”id”:@”12″,@”firstName” : @”Tested”, @”lastName”:@”User”,@”email”:@”[email protected]”,@”age”:@”25″,@”addLine1″:@”T

  • Waneck
    iphone ios opengl-es cocos2d-iphone antialiasing
    I am new to opengl programming, but I am doing something very basic, and the difference of quality between a custom opengl code and cocos2d is huge!I am trying just to load an image and continuously rotate it every frame. With my code, I get a lot of flickering, sharp edges, while cocos2d has it all nice and smooth. I’ve set up 4x Multi-Sampling Anti-Aliasing using apple’s recommended code for iOs 4 on my code, and still it looks very bad in comparison to cocos2d without any MSAA.You can see the

  • LearnCocos2D
    cocos2d-iphone callback game-physics chipmunk cocos2d-iphone-3.0
    I’m using Cocos2d v3 and want to change a body from dynamic to static after colliding with another body. At the moment I’ve got:-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB {_player.physicsBody.type = CCPhysicsBodyTypeStatic; }or-(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB {_player.physicsBody.type = CCPhysicsBodyTypeStatic;return YES; }but neither works. I get

  • Guru
    objective-c cocos2d-iphone core-audio simpleaudioengine
    I read about preloading sounds in SimpleAudioEngine through [[SimpleAudioEngine sharedEngine] preloadEffect:@”bell.wav”];But, with this there are memory leaks which I read on couple of sites. On some websites it was used like this: –(void)loadSoundFilesInBackground {NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];[[SimpleAudioEngine sharedEngine] preloadEffect:@”bell.wav”];[pool release]; }What is the best way to load sound files in background through SimpleAudioEngine ? What is the

  • Tiddly
    iphone ios cocos2d-iphone cocos2d
    I’m using cocos2d for iOS. Not sure if I’m doing something wrong here or if CCParallaxNode does something strange that I just don’t understand.I’m trying to create a few layers of parallax scrolling in the background of my game, at the moment I just have one layer added to the parallax node till I can figure out what’s going wrong. When the game loads the layer it’s always offset down and left by about 30% of the image size. I’ve uploaded an image demonstrating the difference in position here ht

  • kender
    iphone cocoa-touch memory-management cocos2d-iphone
    I have an iPhone application in Cocos2d that sometimes crashes on actual device, due to memory problems. What I have so far found out is that the scenes, when switched, aren’t fully released – the [retainCount] for them is somewhat about 4-10 🙂 The dealloc method never gets called, and then I assume, when I switch the scenes a few times, the memory issue shows up. I’m wondering – where should I relese the scene? Since it has number of children, I suppose I should be doing a cleanup-removal of t

  • LearnCocos2D
    cocos2d-iphone uialertview
    I am trying to lay buttons on top of a background image for a UIAlertView in Cocos2d. Its not working with the code below. any suggestions?UIAlertView *Win=[[UIAlertView alloc] initWithTitle:@”You Win” message:nil delegate:self cancelButtonTitle:@”Next” otherButtonTitles:@”Replay”,@”Quit”, nil];UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-50, -30, 400, 300)];NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathCom

  • White Money
    iphone cocos2d cocos2d-iphone
    I’m wonderring that what’s the difference between ccTouchesCancelled and ccTouchesEnded events in Cocos2d?Thanks! Tien

  • OpenLearner
    cocos2d-iphone cocos2d
    I have a simple CCRotateBy action in a sequence; it is followed by a call to another method which confirms that the CCRotateBy completed (otherwise, that CCCallFunc would not get called in the sequence if CCRotateBy didn’t complete):-(void)correctRotation{if (self.rotationAmount){CCLOG(@”correcting rotation inside: %i”,self.buildNum);CCRotateBy*second=[CCRotateBy actionWithDuration:1 angle:-self.rotationAmount];CCEaseBackInOut*bounce2=[CCEaseBackInOut actionWithAction:second];CCCallFunc*func=[CC

  • 25 revs, 2 users 100%Lukasz
    iphone cocos2d-iphone opengl-es-2.0 alpha blending
    I have very simple CCScene with ONLY 1 CCLayer containing:CCSprite for background with standard blending mode CCRenderTexture to draw paint brushes, with its sprite attached to root CCLayer above background sprite:_bgSprite = [CCSprite spriteWithFile:backgroundPath]; _renderTexture = [CCRenderTexture renderTextureWithWidth:self.contentSize.width height:self.contentSize.height]; [_renderTexture.sprite setBlendFunc:(ccBlendFunc){GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}]; [self addChild:_bgSprite z:-1

  • Geoffroy
    c++ cocos2d-iphone copywithzone
    I have some trouble.I made some interface (abstract class in c++). Implemented it in my class (derived from CCObject too). In third class I try to invoke method of interface and got SIGABORT. Here the code//interface classclass CallBackInterface{public:virtual void SomeMethod() = 0;};//my class that implement the interface class MyClass : public CallBackInterface, public CCObject{public:void SomeMethod(){/*some realization*/}; };//class that invoke the SomeMethodclass CallBacker(){public:CallBa

Web site is in building