I'm having difficulty getting information from the blob class.
All the classes like import "cocos2d.h" are correct. The order goes from bottom up like this: PlayScene -> MotionLayer -> Blob
PlayScene.h
---------
@interface Play : CCLayer {
MotionLayer *motionLayer;
Blob *blob;
}
@property(nonatomic, retain) MotionLayer *motionLayer;
@property(nonatomic, retain) Blob *blob;
PlayScene.m
-----------
@synthesize motionLayer;
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"play.mp3"];
// create and initialize objects for drawing
motionLayer = [MotionLayer node];
// position the objects on the screen
// add the objects as a child to this Layer
[self addChild:motionLayer];
[self schedule:@selector(update:)];
}
return self;
}
- (void)update:(ccTime)dt
{
motionLayer.position=ccp(blob.position.x,blob.position.y); //HMMMMMMMMM
NSLog(@"X: %f", blob.position.x);
NSLog(@"Y: %f", blob.position.y);
}
Blob.h
-----------
@interface Blob : CCSprite {
float vx;
float vy;
float gravity;
}
@property float vx;
@property float vy;
@property float gravity;
- (void)update:(ccTime)dt;
@end
Blob.m
---------
@implementation Blob
@synthesize vx;
@synthesize vy;
@synthesize gravity;
- (id) init
{
self = [super init];
if (self != nil) {
CCSprite *blobimage = [CCSprite spriteWithFile:@"blob.png"];
gravity = 0;
[self addChild:blobimage];
[self schedule:@selector(update:)];
}
return self;
}
- (void)update:(ccTime)dt
{
float x = self.position.x;
float y = self.position.y;
vy += gravity;
x += vx * dt;
y += vy * dt;
self.position = ccp(x, y);
}
@end