Skip to main content

Posts

Showing posts with the label cocos2d-iphone

Cocos2d adding a background image to a layer?

I just finished reading some of the cocos2d documentation, and as far as I understand to add a background image to a layer you have to do something like: Sprite * bg = [Sprite spriteWithFile:@"Background.png"]; [layer addChild:bg z:0]; Allthough as far as my testing goes you can just directly add the sprite to the scene like this: @implementation IntroScene - (id) init { self = [super init]; if (self != nil) { Sprite * bg = [Sprite spriteWithFile:@"Background.png"]; [bg setPosition:ccp(240, 160)]; [self addChild:bg z:0]; [self addChild:[MenuLayer node] z:1]; } return self; } What is the difference between this 2 options, and what is the better way to set a background for a layer?. Any help will be greatly appreciated.

iOS import causing tons of errors?

I'm trying to set up a menu in my cocos2d game and whenever I import Game.h I end up with over 200 errors. It's a cocos2d app with box2d, I'm not sure why it's throwing all these errors though- the game was running perfectly before I swapped loading the Game scene for the MainMenu scene initially. The line of code I'm running is [[CCDirector sharedDirector] replaceScene: [Game node]]; The import of 'Game' causes the errors. Can anyone give me an idea about this? Some information that may be helpful... I originally created the project loading into Game.m but switched it to MainMenu and then import Game.h into MainMenu to access the object. ANY insight is appreciated! Thank you!

CCTMXTiledMap propertiesForGID:(CGPoint)

i m working in cocos2d 0.99.0 my project have a file with name CCTMXTiledMap.h & .m but there is no public method with name propertiesForGID:(CGPoint) so please if u have this method in your cocos2d then please send me code of this method which i can use in .h and .m file. thanx.

Cocos2D iPhone - running actions on multiple targets + callback

I have an array of objects (objArray) and an array of actions (actArray). Both arrays are in order, I mean, object at index 0 of objArray has to perform action 0 on actArray. To make the explanation clear, lets imagine both arrays have 3 objects, obj0, obj1 and obj2. obj0 has to perform action 0 on actArray obj1 has to perform action 1 on actArray obj2 has to perform action 2 on actArray these 3 operations (or n, in the case of the array) have to happen simultaneously. When all animations end, I need the method animationsFinished to be called. How do I do that? I am beginning in Cocos. I have googled around and have not found any practical example around. I have found CCSpan but I don't see how this can be used with multiple objects each one with its own action. thanks.

Cocos2D iPhone - will this save memory?

When you create a sprite on cocos using a texture you allocate memory. Something like: CCTexture2D *textureProxy = [[CCTexture2D alloc] initWithImage:image]; CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; My question is: suppose I want several sprites using the same texture and I do CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy2 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy3 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy4 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy5 = [CCSprite spriteWithTexture:textureProxy]; Will I use 5 times more memory? (or in other words, will the texture be duplicated to each proxy or is the sprite just a "empty box" that references the original texture? If the later is the answer, then the memory usage for similar sprites are not that huge, right? thanks.

App crashing in cocos2d app on device when nothing happening

I have a somewhat simple game that I'm making and now that I'm testing what I consider a bare bone version of the app on devices, I keep getting crashes over and over. I'm fairly new at debugging on actual devices, so any help would be great. The really weird part is that it will usually crash when nothing is firing. No touches, no animations, nothing is happening. I've tried running Instruments to check for memory leaks. All I find are two objects that are both created in the menu scene. I'm changing scenes using Game *game = [Game nodeWithPlayers:arr Tutorial:NO]; [[CCDirector sharedDirector] replaceScene:game]; which sends some data (mainly # of players) to the Game scene. I put a comment in the dealloc of my menu scene and it fires, so I know that's happening. The two objects that are reported as memory leaks are my MenuManager object that helps w/ some menu animations and positions in the menu scene, and my SoundManager object which at the moment