PDA

View Full Version : EAGLView can't call methods from other class




PizzaTray
Oct 31, 2009, 12:15 PM
From some reason I can't call functions from other classes in the GLView.m,
and if I put the methods in the GLView.m class - everything works great.

EAGLView.m class:




#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import <mach/mach.h>
#import <mach/mach_time.h>
#import "EAGLView.h"

#define USE_DEPTH_BUFFER 0

@interface EAGLView ()

@property (nonatomic, retain) EAGLContext *context;

- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;
- (void) updateScene:(float)delta;
- (void) renderScene;
- (void) initGame;
- (void) initOpenGL;

@end

@implementation EAGLView

@synthesize context;

+ (Class)layerClass {
return [CAEAGLLayer class];
}

- (id)initWithCoder:(NSCoder*)coder {
.
. bla bla
.
}
.
[self initGame];
.
}
}

- (void)initGame {
.
. yade yade
.
[monst initMonst]; can't call the method -initMonst
.
.
}

- (void)mainGameLoop {
.
.
}

- (void)updateScene:(float)delta {
.
.
}

- (void)renderScene {
.
. gl bla bla
.
[monst render]; can't call the method -render
.
.
}

- (void)initOpenGL {
.
.
}

- (void)layoutSubviews {
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
[self createFramebuffer];
[self renderScene];
}

- (BOOL)createFramebuffer {
.
.
}

- (void)startAnimation {
gameLoopTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60 target:self selector:@selector(mainGameLoop) userInfo:nil repeats:YES];
}
- (void)destroyFramebuffer {
.
.
}
-(void) accelerometer:(UIAccelerometer *) acc didAccelerate:(UIAcceleration *) acceleration {
[monst accelMonster:acc didAccelMonster:acceleration];
}
- (void)dealloc {
if ([EAGLContext currentContext] == context) {
[EAGLContext setCurrentContext:nil];
}
[context release];
[super dealloc];
}
@end



Monster.m Class:



#import "Monster.h"

@implementation Monster

@synthesize img;
@synthesize ssMonster;
@synthesize anim;
@synthesize location;
@synthesize r;

- (void) initMonst {

self.img = [[Image alloc]initWithImage:[UIImage imageNamed: @"playerRobot.png"] filter:GL_NEAREST];
[self.img setAlpha:1.0f];

location = CGPointMake(MONST_START_LOCATION_X,480-MONST_START_LOCATION_Y);
r = MONST_RADIUS;
}

- (void) accelMonster:(UIAccelerometer *) acc didAccelMonster:(UIAcceleration *) acceleration {

//TODO: add diagonal movements

if(acceleration.z > -1.07 && acceleration.z < -0.9){
rightMove = NO;
leftMove = NO;
upMove = NO;
downMove = NO;
}

if(acceleration.y > 0.14){
rightMove = YES;
leftMove = NO;
upMove = NO;
downMove = NO;
}
if(acceleration.y < -0.25){
rightMove = NO;
leftMove = YES;
upMove = NO;
downMove = NO;
}
if(acceleration.x < 0.155){
rightMove = NO;
leftMove = NO;
upMove = YES;
downMove = NO;
}
if(acceleration.x >0.77){
rightMove = NO;
leftMove = NO;
upMove = NO;
downMove = YES;
}
}

- (void) updateMovement:(float)delta {

//TODO: add diagonal movements

if(upMove){
location.x -= MONST_SPEED*delta;
}
if(downMove){
location.x += MONST_SPEED*delta;
}
if(rightMove){
location.y += MONST_SPEED*delta;
}
if(leftMove){
location.y -= MONST_SPEED*delta;
}
}

- (void) animateShooting {
//TODO
;
}

- (void) animateDeath {
//TODO
;
}

- (void)render {
[self.img renderAtPoint:CGPointMake(100,100) centerOfImage:YES];
}

- (void)dealloc {
[self.img release];
[super dealloc];
}

@end



what should i do?



wlh99
Oct 31, 2009, 01:24 PM
Are you creating an instance of Monster called monst anywhere?
Something like:

Monster monst;
monst = [Monster alloc];
[monst initMonst];

PizzaTray
Oct 31, 2009, 01:43 PM
Are you creating an instance of Monster called monst anywhere?
Something like:

Monster monst;
monst = [Monster alloc];
[monst initMonst];


Can't belive it, i forgot the alloc X.X,
two months of programming and i'm still "objective-c dumb".

Thanks a lot!