cocos2d-iphone

Cocos2d addSpringToBody

Any ideas how this addSpringToBody works? cpConstraint *joint = [space addSpringToBody:block fromBody:ball2 toBodyAnchor:cpvzero fromBodyAnchor:cpvzero restLength:0.0f stiffness:1.0f damping:0.0f]; cpConstraintNode *jointNode = [cpConstraintNode nodeWithConstraint:joint]; jointNode.color = ccWHITE; jointNode.lineWidth...

How to draw a background fast in cocos2d?

I'm toying with a small game on my iPad using cocos2d and I've run into some performance worries. I have a 512x512 image tiled as my background. That gives me around 40fps with 20 sprites (in a CCSpriteBatchNode), the code for the background is this: CCSprite *background; background = [CCSprite spriteWithFile:@"oak.png" rect : CGRectMa...

Calling Objective C Instance Method from Another Class

I have class called "HelloWorld.m" and another class called "Person.m". I have declared Person instance in the HelloWorld.m class as follows: Person *person; Now, when the user touches the screen I fire the following method: [person foo]; But I get the error saying invalid selector sent. NOTE: Person class inherits from the CCS...

Calling Instance Method from the Objective C Selector

Is it possible to call the instance method of an object from the selector? Is the below possible? It gives me compilation error that ":" is missing or something: timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(([self.perso...

iphone sdk 4.1 memory leackage: may be scene replace problem (cocos2d)

I have used scheduler to return from a scene to the main menu. There is nothing in the scene page except menu. But scenes are not deallocating and memory leakage increasing as i navigate through the scenes. So application is not closing(kept running in background when close using iphone/ipod button) but crashing. Hope some of you faced ...

box2d:Move body with animation

Hi, i am using box2d to developed iphone game.But i have not a lot of experience.I move a body to a location using this code body->SetTransform(b2Vec2(posx2,posy2), 0); and the body does move.But i need it to move with animation.in objective c i use UIView Animation to do similar type of things. can anyone tell how it possible in coc...

water effect in cocos2d

Hi, I'd like to have a water effect on a background layer in my app. The effect doesn't need to react to touch or anything - it just needs to wave an image a little bit. CCWaves3D seem ok, but leave have nasty black artifacts around the edges when I run it. Similarly CCShaky3D. CCLiquid brings my app down from 20fps to 5fps.. Is there ...

zoom particular portion

Hi!!there.. I am trying to make a game in ipad using cocos2d. For that, I used viewcontroller class and took an imageview using scrollview. Now how can I zoom a particular portion of an image?? Anybody there,please give me a code or a demo or guide me. Thank you... ...

How to rotate and resize sprite like photo in lybrary

How can I rotate sprite around his center in cocos2d in ccTouchesMoved. I found some code, but this not what I need. I need to rotate sprite like photo in Photo gallery app. - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSArray *allTouch = [touches allObjects]; if([allTouch count] > 1){ UITouch *t...

cocos2d-iphone setBlendFunc()

Here is what my code look like CCSprite *sp = [CCSprite spriteWithFile:@"textureWithOneColorbackground.jpg"]; [self addChild:sp]; // Change the blending factors [sp setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}]; [sp setColor:ccBLACK]; The original texture color is (246,149,32) The outcome now is (0, 0, 0) According to OpenGL, the cal...

How to creating custom dialog boxes with cocos2d?

1、top http:// i.imgur.com/LszAu.png 2、middle http:// i.imgur.com/j82Dr.png 3、bottom http:// i.imgur.com/OP9hu.png dialog http:// i.imgur.com/ed3W2.png How do i do with 1,2,3 to a dialog? And dialog can stretch with content? I hope you can write a simple example for me~~thanks! ...

Best way to zoom and pan a 2D cocos2d iphone game

What's the best way to implement a pan-able zoomable game map with Cocos2d for iPhone. It would be like Mobile Safari except with a game map that doesn't fit completely on screen. Or like how it's done with Angry Birds, Cut the rope, etc. This would not be a side scrolling game, just a fixed game area that you can zoom in/out of. I'm n...

create a texture from a spritesheet cocos2d

Hey all Basically all i want is to create CCTexture2D objects from a spritesheet. I can make individual sprites from charSpriteCur = [CCSprite spriteWithTexture:charSheet.texture rect:CGRectMake(136, 0, 136, 223)]; but i want to get individual textures from a spritesheet so that i can use [mySprite setTexture:tex]; to change the spr...

How to implement HD "Retina Display" graphics in Cocos2D

Hello, I am not quite sure how use HD images for sprites in cocos2d. I looked through the documentation, and downloaded the newest beta which supports points instead of pixels, but I don't understand the whole -hd suffix idea. In other word I need help and have no idea how to use retina quality graphics in my cocos2d game. I feel tha...

How to update cocos2d?

I've been using an older version of cocos2d for iPhone for an existing project - never change a running system. Now I'd like to upgrade to a more recent version and don't know how I should proceed about this. Just install a newer version? Will the install script overwrite all of the old files and take care of the old templates too? Or d...

NSObject inherited class crashes the application

Hi all! I'm new in objective-C and here is my problem: I want to write a game and i want to use a GameStateManager class to manage the game states. As i've read every class in Objective-C should be inherited from NSObject or it's subclass. So here is the GameStateManager interface: @interface GameStateManager : NSObject { int curren...

NSMutableArray EXC_BAD_ACCESS when i try read from it

I want update position of Particles for store this information I use NSMutableArray. I want do update 1 time per 2 seconds for example. For this I try use this code. //ParticlesLayer.h @interface ParticlesLayer : CCLayer { CCQuadParticleSystem *particle; NSMutableArray *partilesCoordinates; } @property (assign, readwrite) NSMutableArra...

CCSprite Aniamtion problem: Loop movement- [enter from left exit through right] do this actions forever

Here is my code, i have been trying- -(void) animatedMove:(CCSprite *)character { ccTime actualDuration = 10; id actionMove = [CCMoveBy actionWithDuration:actualDuration position:ccp(screen_width+50, character.position.y)]; id actionBack = [CCMoveBy actionWithDuration:1 ...

About integers and memory management in Objective-C

I have this code in one of my projects (part of a loop): newPath = [tileMap updatePathFromNode:point1 toNode:point2]; int x,y; x = [[newPath objectAtIndex:0] nodeX]; y = [[newPath objectAtIndex:0] nodeY]; currFiend.motionTarget = ccp(x*20,y*20); I am now looking for areas around my entire project to optimize the code. What i'm curiou...

How to make a moving object "stick" to a stationary object in box2D

Hello, I have been experimenting with the box2D sample project within cocos2D for the iPhone and am wondering if box2D is the appropriate engine to use to make a moving object "stick" to a stationary object when the moving object is finished moving in a certain direction. Here is a simplification of what I am trying to achieve: I hav...