FAQ Database Discussion Community


Finding nearest points with Chipmunk and cocos2d

ios,cocos2d-iphone,chipmunk
Using cocos2d and chipmunk, I try to get the different object around a sprite (for example a bomb) so that I can apply an impulse on these. I first added this on top of my project: #import "ObjectiveChipmunk/ObjectiveChipmunk.h" #import "CCPhysics+ObjectiveChipmunk.h" And then the code: ChipmunkSpace *space = [_physicsNode space]; cpVect...

What's the best way to use IF and SWITCH together for game levels?

ios,objective-c,cocos2d-iphone,int,switch-statement
I have the following code working correctly in my game project where a ball is randomly shown to the player. int random = arc4random_uniform(5); switch (random) { case 0: { NSLog(@"Case 0 Ball"); } break; case 1: { NSLog(@"Case 1 Big Ball"); break; } case 2: { NSLog(@"Case 2 Center...

Game Centre Leaderboard - Can't set GKLeaderboardViewController delegate to self (CCLayer)

ios,objective-c,cocos2d-iphone,game-center
The following code won't compile because of the error that results from trying to set the GKLeaderboardViewController delegate to the calling instance. The error message is: Assigning to 'id<UINavigationControllerDelegate>' from incompatible type 'MainMenu *' where MainMenu is of type CCLayer. If the assignment statement (leaderboard.delegate = self) is commented out,...

CCParallaxNode moves on and convertToWorldSpace give wrong values cocos2d iPhone

ios,objective-c,iphone,cocos2d-iphone,cocos2d-x
I have used the code below for collision detection. but as CCParallaxNode moves on in infinite scrolling. my positions goes wrong. i have tries every possible solution till yet. but everything gives me wrong values in parallax. for (CCSprite *sp in PathsArray) { if (sp.tag==500) { CGPoint sprect=[self convertToWorldSpace:sp.position]; CGRect...

How to perform action on “Touch inside” on button in Cocos2d

cocos2d-iphone
I am trying to perform action like changing color of label, when user touches the button but I am unable to find the correct solution in Cocos2d. Regards...

Prevent user from jumping in mid-air

objective-c,cocos2d-iphone
I'm trying to prevent a sprite from jumping again in mid-air. However, the way I'm implementing it is wrong, and I'm really lost. -(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CCActionJumpBy *jump_up = [CCActionJumpBy actionWithDuration:1.0f position:ccp(0, 100) height:50 jumps:1]; [player runAction:jump_up]; CCActionJumpBy *come_down = [CCActionJumpBy actionWithDuration:1.0f position:ccp(0, -100) height:50 jumps:1]; [player...

How to create Spot Light Effect in cocos2d-x

cocos2d-iphone,cocos2d-x
I am creating a game in cocos2d-x and want to create spotlight effect in it on my character. Is there any way to do it without using OpenGl? if not how can i do it with openGL? Thanks in Advance...

timing issues while creating replay of game (ghost for racing)

ios,objective-c,cocos2d-iphone,box2d,game-physics
I have created an iOS game in cocos2d that uses box2d for physics. I would like to have a replay function for this game (where you can race a ghost of your previous attempts) I know box2d is deterministic (well it is for the same hardware... so running this on...

place CCSprite by percentage

cocos2d-iphone,ccsprite
I am searching for a way to place a sprite via objective-c in percentage based on the parents dimensions. Is there any way?

How to use Cocos2d-Swift in existing project

ios,swift,cocos2d-iphone
I got an existing Objective-C project. Now I decided to rewrite some code and add Cocos2d to it. I know this framework for a long time and I recently discovered that they stopped the support for Cocos2d and created a new version called Cocos2d-x. There I found the Swift library...

CCSpine by cocos2d-objc-ext not working

cocos2d-iphone,cocos2d-iphone-3,cocos2d-swift
I am trying to use CCSpine in my cocos2d-swift V3.3 project, there is a issue: not found CCDictionary.h Where is the CCDictionary.h? Dose it in a low version of coco2d-iphone?But I didn't find it.

how to replace the deprecated cc_content_scale_factor()

ios,cocos2d-iphone
My platform is cocos2D V3.x and iOS. I am using CC_CONTENT_SCALE_FACTOR() function to append to detect device requirement and apply prefix accordingly but it showing cc_content_scale_factor() is deprecated. if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if( CC_CONTENT_SCALE_FACTOR() == 2 ) lstrNameToReturn = [lstrNameToReturn stringByAppendingString:@"-ipadhd"]; else lstrNameToReturn = [lstrNameToReturn stringByAppendingString:@"-ipad"]; } else {...

Cocos2dx Android and IOS build

cocos2d-iphone,cocos2d-x,cocos2d-x-3.0
I have downloaded latest version of cocos2d-x from this link. And worked on Visual Studio Environment and finished. Now I am going to build it to Android and IOS for extra processes. What can I do?...

Cocos2d Node not accepting Touches

ios,cocos2d-iphone,touch,visibility,ccnode
Cocos2d v3: I have a very strange problem. I have a dozen or so CCNodes that are acting like menus for my game. They take up just a small section of the center of the screen. To present one node I hide (node.visible = NO) all the other nodes. Two...

How Do I know the current cocos2d version within my project?

ios,cocos2d-iphone
I do have the 3.0 version template installed which is displayed in the xcode new project wizard, however I have an old project which is not 3.0 but I have to idea which version it is. any help?...

How to make sprites respond to contact events but not collision events (SpriteKit)?

ios,swift,cocos2d-iphone,sprite-kit
Is it possible to make sprites in Swift respond only to contact events, ignoring collision events? We set the dynamic property to false for one of the sprites, but it didn't trigger the didBeginContact method when another sprite contacted it. In other words, we want to get notified in didBeginContact...

Tilemap displaying incorrectly on iOS using Cocos2D

ios,cocos2d-iphone,spritebuilder,tiled
I used Tiled to create a tilemap to use in one of my games for iOS; however, it displays incorrectly when I run it. I've tried making multiple different .tmx files with different file sizes for phone, phonehd, tablet, and tablethd. The tilemap is base64 zlib compressed, but I've also...

CCPhysicsCollisionDelegate not called

cocos2d-iphone,spritebuilder
I'm stuck for 2 days now on collision detection. I tried every solution suggested in the forums, and the collision delegate methods are still not being called called. I'm using cocos2d v3.4 bundled with SpriteBuilder v1.4.7. Here is my simple test: smallBox and bigBox are both children of _physicsNode 1-...

How do we enumerate and modify positions array of CCsprite inside Update method?

cocos2d-iphone,ccsprite
How do we enumerate and alter our object's position (contained in array) for each delta time? I put some CCsprite objects inside array, then I displayed them in scene, but also I wanted to make them move with modifying update method, I failed on last part. How do I get...

Realm not writing correctly

ios,swift,cocos2d-iphone,realm
I've been trying to use Realm to create a db for my cocos2d game, but can't figure out some problem. I'm using Realm Objective-C 0.92.3 (https://realm.io/docs/objc/latest/) since I need my game to work on iOS 7 or later. I've been using some small code to write and read but somehow...

Cocos2d on iOS: EXC_BAD_ACCESS in CCGraphicsBufferGLUnsynchronized when leaving app after ad

ios,cocos2d-iphone,crash,interstitial
I have integrated the SKD of UnityAds into my game to show full screen interstitial video ads. When the video is finished, a link to the AppStore is provided by the ad framework. When I select this link, the AppStore is opened. My app crashes in this moment, throwing EXC_BAD_ACCESS...

Cocos2D v3 CCTableView not scrolling

ios,cocos2d-iphone,spritebuilder,ccscrollview
I am trying to use a CCTableView in my game. You should be able to scroll through a list of names. I am able to click on a cell and log the which cell was clicked. However when I try to scroll there is no movement. @interface WSMPlayerCandidateSubMenu(){ CCNodeColor *_candidateSubMenuSprite;...

Mutating method sent to immutable object closes app

ios,objective-c,cocos2d-iphone
In my code ,when the user completes a level, it unlocks the next level (out of a total of 15 levels). However, I have noticed that, when I complete the level, first time, it works, however, when I go back to it and try again, it crashes with this error;...

Set background color Text Field on cocos2d-x-3.3beta0

cocos2d-iphone,cocos2d-x
I am creating a text using Text class like below using cocos2d-x-3.3beta0. Text* MessageText = Text::create(message, FONT, FONT_SIZE); I have set the size of text area MessageText ->setTextAreaSize(Size(100,150)); Now i want to color text area which is background of text . Is there any way to do this? Thanks...

Admob Interstitial Cocos2d Objective C

ios,objective-c,xcode,cocos2d-iphone,admob
i'm searching on google but i only find the way to integrate the AdMob Banner View on my app in Cocos2d. Now I need to put the full screen AdMob interstitial and i don't find the way to do it :. Please Help me, how i can do it?? I'm...

Strange artefacts appear on CCSprite

cocos2d-iphone,artifacts,texturepacker
I have a CCLayer class imported onto a game layer strangely all the the sprites have "artefacts" that seem to appear from nowhere since I have checked and re-exported all of the files Is some setting or something else that could cause this to happen? I'm new at this but...

Throwing exception due to CCBlock?

cocos2d-iphone
I'm using some code from RAYWENDERLICH, which is a great site, but thats not the point. The code that I got off the site that is given me a hard time is this (Im adding a monster/ghost that is supposed to move on the screen): - (void) addMonster { CCSprite...

CCPhysicsBody Collision not working in cocos2d-swift v3.4

iphone,cocos2d-iphone,chipmunk
Here is code: @interface MainScene : CCNode<CCPhysicsCollisionDelegate> //.m -(void)onEnter { [super onEnter]; mPhysicsWorld = [CCPhysicsNode node]; mPhysicsWorld.gravity = ccp(0,0); mPhysicsWorld.debugDraw = YES; mPhysicsWorld.collisionDelegate = self; [self addChild:mPhysicsWorld]; //Body_A { CCSprite *sprite = [CCSprite spriteWithImageNamed:@"sprite_1.png"]; sprite.position = ccp(280, 220); sprite.rotation = 13; sprite.name = @"Body_A"; [email protected]"Group1"; [email protected]"typeA"; CGRect...

unable to resize image properly

ios,objective-c,cocos2d-iphone,uiimage
I am having problem with UIImage resizing, image masking is working fine but after applying mask UIImage is starched, the problem is with scaling as image is not scaled properly. CCClippingNode *clippingNode = [[CCClippingNode alloc] initWithStencil:pMaskingFrame ]; pTobeMasked.scaleX = (float)pMaskingFrame.contentSize.width / (float)pTobeMasked.contentSize.width; pTobeMasked.scaleY = (float)pMaskingFrame.contentSize.height / (float)pTobeMasked.contentSize.height; clippingNode.alphaThreshold = 0;...

Cocos2d-Swift v3.x Sprite Builder : In iPad iPhone sd images are used. -ipad suffix ignored

cocos2d-iphone,cocos2d-swift
Code: var bg = CCSprite(imageNamed:"Background.png") Images used in Resource: Background-hd.png Background-ipad.png Background-ipadhd.png Background-iphone5hd.png Background.png In all device Background.png(320x480) used, other images are ignored. How to fix this ? Retina display is not enabled...How to enable retina display in v3 ? Here is working sample code with this problem. ...

How to play a BGM and know current playback time on in cocos2d ios?

ios,objective-c,cocos2d-iphone
I'm working on a IOS game based on music, and a strict synchronize between background music and global timer is necessary, so I'm looking for some way to play music AND at the same time knowing which exact position the music is playing on at each frame update. the OALSimpleAudio...

How to save multiple time values in NSUserDefaults, Cocos2d

ios,objective-c,cocos2d-iphone
I have a question in regards to saving the high score in my game using NSUserDefaults. The thing is that the players score is their time and the way I'v added the time can be seen below: _countTime = 0; _text = [CCLabelTTF labelWithString:[NSString stringWithFormat:@" %02i", self.countTime] fontName:@"American Typewriter" fontSize:24];...

CCClippingnode causes OpenGL error 0x0502

ios,objective-c,cocos2d-iphone,opengl-es,ccsprite
I'm using cocos2d-iPhone v.2.2, updating an old game, and I have a clipping node that is causing an error. In AppDelegate.m, I switched the settings to use CCClippingNode: CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds] pixelFormat:kEAGLColorFormatRGB565 depthFormat:GL_DEPTH24_STENCIL8_OES //switched from 0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; And then I used this code to...

Objective C for loop delay

objective-c,for-loop,cocos2d-iphone,delay,grand-central-dispatch
I have a for loop that I want to add a delay between iterations. I have changed waitUntilDone to YES and get the same results. My array only has two numbers in it and both are called after the five seconds instead of: 0s - nothing 5s - Block called...