Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-15-2011, 09:16 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 46
NorthCode is on a distinguished road
Default Game crashes when i try to utilize the features of a b2Body in my NSObject class, why

My app crashes when i try to use the features of b2Body from within my NSObject class.

Here is the interface of my class:

Code:
#import <Foundation/Foundation.h>

#import "Box2D.h"
#import "GLES-Render.h"
#import "cocos2d.h"
#import "HelloWorldScene.h"


@interface Magnet : NSObject {


b2Body* body;

}
@property (readwrite,assign) b2Body* body;
@end
And here is how i declare it in HelloWorldScene.h:

Code:
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import <UIKit/UIKit.h>
#import "Magnet.h"

@class Magnet;

@interface HelloWorld : CCLayer
{
b2World* world;
GLESDebugDraw *m_debugDraw;



 Magnet *magnet;

}
And here is how i access the b2Body in magnet, in HelloWorldScene.mm:

Code:
b2BodyDef bodyDef2;
bodyDef2.type = b2_staticBody;

bodyDef2.position.Set(300/PTM_RATIO, 150/PTM_RATIO);
bodyDef2.userData = sprite2;
magnet.body = world->CreateBody(&bodyDef2);

// Define another box shape for our dynamic body.
//b2PolygonShape dynamicBox;
b2CircleShape dynamicBox2;

//dynamicBox.SetAsBox(1.0f, 1.0f);//These are mid points for our 1m box
dynamicBox2.m_radius = 0.49;
// Define the dynamic body fixture.
b2FixtureDef fixtureDef2;

fixtureDef2.shape = &dynamicBox2;   


fixtureDef2.density = 1.3f;
fixtureDef2.friction = 1.0f;


magnet.body->CreateFixture(&fixtureDef2);
Is there any problem with my code?

Im receiving a SIGABRT in the Box2D sourcefiles in the CreateFixture() function... What should I do?
NorthCode is offline   Reply With Quote
Old 05-15-2011, 04:57 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 46
NorthCode is on a distinguished road
Default ..

I have been struggling with this for a while, it works when i use a regular b2Body (outside the class), but the second it becomes a property of "Magnet" it doesnt work. I cant see whats different between the two, do I have to init it within the class or something? Please help.
NorthCode is offline   Reply With Quote
Old 05-16-2011, 06:32 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 46
NorthCode is on a distinguished road
Default ..

Has anyone done this? (creating class with b2Body), Box2D being C++ gets really confusing when using Objective-C classes..
NorthCode is offline   Reply With Quote
Old 06-01-2011, 02:41 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 15
anorak is on a distinguished road
Default

Have you tried creating the body separately, then setting "magnet.body = <body created separately>"?
anorak is offline   Reply With Quote
Reply

Bookmarks

Tags
box2d, class, cocos2d, nsobject

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 421
7 members and 414 guests
AppleDev, chemistry, Emy, hussain1982, mistergreen2011, Retouchable, skrew88
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,922
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0