How To Make A Simple iPhone Game with Cocos2D Tutorial
How To Make A Simple iPhone Game with Cocos2D Tutorial
This is the official thread to discuss the following blog post: How To Make A Simple iPhone Game with Cocos2D Tutorial
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
Hi, Ray and all developers! Please, help me to understand why [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"music_bg.mp3"] and [[SimpleAudioEngine sharedEngine] playEffect:@"effect1.mp3"] give memory leaks? What is the best for usage mp3 or caf format?
- dyulyur
- Baby Hacker
- Posts: 5
- Joined: Fri Dec 24, 2010 11:05 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
Not sure about the memory leaks. But CAF format is the preferred data format for sounds on the iPhone, see this guide for some more info:
http://www.raywenderlich.com/204/audio-101-for-iphone-developers-file-and-data-formats
http://www.raywenderlich.com/204/audio-101-for-iphone-developers-file-and-data-formats
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
Thank you very much for your great help, Ray!
- dyulyur
- Baby Hacker
- Posts: 5
- Joined: Fri Dec 24, 2010 11:05 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
Hello, Ray! I really need your help because nobody has answer. My problem is the initial Hello World cocos2d project. It gives memory leaks as you can see with XCode -> Run with performance tool -> Leaks
http://efreedom.com/Question/1-3668558/Cocos2d-Hello-World-Application-Leaking-Bytes How to eliminate this problem? Please, if you know something answer me.
http://efreedom.com/Question/1-3668558/Cocos2d-Hello-World-Application-Leaking-Bytes How to eliminate this problem? Please, if you know something answer me.
- dyulyur
- Baby Hacker
- Posts: 5
- Joined: Fri Dec 24, 2010 11:05 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
why changing the class to CCColorLayer and change in init if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
the background remain black? (i added a breakpoint su super initWithColo and it is executed) i have just tried on the last build (0.95) something changed? i created a layer CCColorLayer and added as subview and it work, but why not work as you said?
the background remain black? (i added a breakpoint su super initWithColo and it is executed) i have just tried on the last build (0.95) something changed? i created a layer CCColorLayer and added as subview and it work, but why not work as you said?
- dany88
- n00b
- Posts: 4
- Joined: Wed Dec 29, 2010 12:50 pm
- Has thanked: 0 time
- Been thanked: 0 time
- simonkinghk999
- n00b
- Posts: 2
- Joined: Mon Jan 03, 2011 9:37 am
- Has thanked: 0 time
- Been thanked: 0 time
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
@dany88: Hm, I just made a test project with the latest version of Cocos2D - changed HelloWorld to be CCColorLayer and replaced the first line in init with the following:
And the background is now red. That doesn't work for you?
- Code: Select all
if( (self=[super initWithColor:ccc4(255, 0, 0, 255)] )) {
And the background is now red. That doesn't work for you?
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
Hey great tutorial!
I know I have a very simple/NOOB problem on my hands - but I'm unclear as to how resolve it - if anyone could reply, I'd be very appreciative.
My problem deals with the dreaded Memory Management monster.
I have a scenario much like the above tutorial where I am capturing objects to destroy (once collision occurs) in an array and then trying to release them in the Update method.
Here is my Update Method:
...where GameObject is a subclass of CCSprite and toBeDestroyed is a NSMutableArray. GameObject's removeSprite method looks like this...
..and GameObject also has another method like this...
..that is called in dealloc....
Why do I get EXC_BAD_ACCESS when I try to call "removeAllObjects" on my array?
thanks,
Monty
I know I have a very simple/NOOB problem on my hands - but I'm unclear as to how resolve it - if anyone could reply, I'd be very appreciative.
My problem deals with the dreaded Memory Management monster.
I have a scenario much like the above tutorial where I am capturing objects to destroy (once collision occurs) in an array and then trying to release them in the Update method.
Here is my Update Method:
- Code: Select all
-(void) update:(ccTime)delta
{
for(GameObject *obj in toBeDestroyed)
{
[obj removeSprite];
}
[toBeDestroyed removeAllObjects];
}
...where GameObject is a subclass of CCSprite and toBeDestroyed is a NSMutableArray. GameObject's removeSprite method looks like this...
- Code: Select all
-(void)removeSprite;
{
GameScene *game = [GameScene sharedGameScene];
[game removeChild:self cleanup:YES];
}
..and GameObject also has another method like this...
- Code: Select all
-(void)removeBody
{
if(self.spriteBody != nil)
{
b2World *world = spriteBody->GetWorld();
world->DestroyBody(spriteBody);
spriteBody = NULL;
}
}
..that is called in dealloc....
- Code: Select all
-(void) dealloc
{
[self removeBody];
// don't forget to call "super dealloc"
[super dealloc];
}
Why do I get EXC_BAD_ACCESS when I try to call "removeAllObjects" on my array?
thanks,
Monty
- montymccune
- n00b
- Posts: 1
- Joined: Mon Jan 03, 2011 9:26 pm
- Has thanked: 0 time
- Been thanked: 0 time
Re: How To Make A Simple iPhone Game with Cocos2D Tutorial
@Monty: Hm, not sure offhand... usually that would indicate that something is being double deallocced somewhere... one good way to test for that is to set the NSZombieEnabled flag and checking for warnings, as indicated here: http://www.cocoadev.com/index.pl?NSZombieEnabled
Another good thing to try is Build\Build and Analyze, which often helps you identify problem spots.
If you try those and still can't get anywhere, post or email me your project and I'll take a quick look.
Another good thing to try is Build\Build and Analyze, which often helps you identify problem spots.
If you try those and still can't get anywhere, post or email me your project and I'll take a quick look.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Who is online
Users browsing this forum: No registered users and 4 guests