Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
4 posts
• Page 1 of 1
Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
This is the official thread to discuss the following blog post: Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
Hi, i'm new to Box2D. This is a great tutorial!!!
But I found this problem:
the article uses the lines
[self setTouchEnabled:YES]; and [self setAccelerometerEnabled:YES]
and XCode tells me tha these methods are "not found".
At the begininng I didn't understand the warnings but then i found that the correct lines for me are:
[self setIsTouchEnabled:YES]; and [self setIsAccelerometerEnabled:YES];
Now the code work properly!
I just want to share this problem with all of you!
Bye
Nic
But I found this problem:
the article uses the lines
[self setTouchEnabled:YES]; and [self setAccelerometerEnabled:YES]
and XCode tells me tha these methods are "not found".
At the begininng I didn't understand the warnings but then i found that the correct lines for me are:
[self setIsTouchEnabled:YES]; and [self setIsAccelerometerEnabled:YES];
Now the code work properly!
I just want to share this problem with all of you!
Bye
Nic
Re: Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
Hi, I'm new to Objective-C, Xcode, Cocos2D and Box2D. My question is do we need to learn C++ in order to use Box2D. The tutorial doesn't make any mention of C++ but the Box2D part is written in C++, right? The files are .mm extension but the code just seems to be mixed into the usual Objective-C functions. So, if you want to use Box2D with an obj-c app do you have to learn C++ first?
- ptc79
- n00b
- Posts: 2
- Joined: Mon Feb 25, 2013 5:24 pm
- Has thanked: 0 time
- Been thanked: 0 time
Re: Intro to Box2D with Cocos2D 2.X Tutorial: Bouncing Balls
Hello,
I'm trying to add more balls with a button click.
I wrote this:
But it won't add any new balls if I press on the button.
Do I have to tell the program that there's a new body it has to deal with or anything if it's not created in the init method?
~VitalRemains
I'm trying to add more balls with a button click.
I wrote this:
- Code: Select all
[...]
CCMenuItem *addMenuItem = [CCMenuItemImage itemWithNormalImage:@"ButtonPlus.png" selectedImage:@"ButtonPlusSel.png" target:self selector:@selector(addNewBall)];
addMenuItem.position = ccp(winSize.width - (addMenuItem.contentSize.width/2), winSize.height - (addMenuItem.contentSize.height/2));
CCMenu *addMenu = [CCMenu menuWithItems:addMenuItem, nil];
addMenu.position = CGPointZero;
[self addChild:addMenu];
[...]
- (void)addNewBall {
CCSprite* newBall = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 52, 52)];
newBall.position = ccp(0, 300);
[self addChild:newBall];
b2Body* newBallBody;
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(0/PTM_RATIO, 300/PTM_RATIO);
ballBodyDef.userData = newBall;
newBallBody = _world->CreateBody(&ballBodyDef);
b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 0.2f;
ballShapeDef.restitution = 0.8f;
newBallBody->CreateFixture(&ballShapeDef);
}
But it won't add any new balls if I press on the button.
Do I have to tell the program that there's a new body it has to deal with or anything if it's not created in the init method?
~VitalRemains
- VitalRemains
- n00b
- Posts: 1
- Joined: Fri Mar 29, 2013 10:50 pm
- Has thanked: 0 time
- Been thanked: 0 time
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests