Note that there are some explanatory texts on larger screens.

plurals
  1. POCommunication between 2 CClayers
    primarykey
    data
    text
    <p>//in Class A.h -> CODE:</p> <pre><code>#import "B.h"; #import "cocos2d.h" #import "Box2D.h" #import "GLES-Render.h" #import "LevelHelperLoader.h" #import "ContactListener.h" #import "KKGameKitHelper.h" #import "LevelHelper.h" @interface A : CCLayer { b2World* world; GLESDebugDraw* debugDraw; LevelHelperLoader * lh; B * b; //another class } +(id) scene; @end </code></pre> <p>In Class A.m -> CODE: </p> <pre><code>@implementation A +(id) scene { CCScene *scene = [CCScene node]; A *layer = [A node]; [scene addChild: layer]; //add another layer B * anotherLayer=[B node]; [scene addChild:anotherLayer]; layer.b=anotherLayer; [layer.b createBullets]; return scene; } -(id) init { if ((self = [super init])) { self.isTouchEnabled = YES; glClearColor(0.1f, 0.0f, 0.2f, 1.0f); // Construct a world object, which will hold and simulate the rigid bodies. b2Vec2 gravity = b2Vec2(0.0f, 0.0f); world = new b2World(gravity); world-&gt;SetAllowSleeping(YES); //world-&gt;SetContinuousPhysics(YES); NSString* currentLevel = [[LevelManager sharedInstance] activeLevel]; lh = [[LevelHelperLoader alloc] initWithContentOfFile:currentLevel]; //creating the objects [lh addObjectsToWorld:world cocos2dLayer:self]; if([lh hasPhysicBoundaries]) [lh createPhysicBoundaries:world]; if(![lh isGravityZero]) [lh createGravity:world]; [self scheduleUpdate]; } return self; } -(LevelHelperLoader *) getLh { return lh; } </code></pre> <p>//in B.h CODE: </p> <pre><code>@interface B : CCLayer { LHSprite * sprite1; b2Body *body; } </code></pre> <p>//in B.m CODE:</p> <pre><code>#import "B.h" #import "A.h" @implementation B -(id) init { if ((self=[super init]) ) { CCLOG(@" B init..."); } return self; } -(void ) createBullets { A * mainClass=[[A alloc]init]; sprite1= [[mainClass getLh] createPhysicalSpriteWithUniqueName:@"img"]; body=[sprite1 body]; [self addChild:sprite1]; [sprite1 transformPosition:ccp(150,250)]; } @end </code></pre> <p>By doing, all this stuff i am able to add LHSprite from another class (i.e class B) but not it's body. What Changes should i make,to add the body for LHSprite i added?</p> <p>Kind Regards, Stack.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload