EAGLView can't call methods from other class

Discussion in 'iOS Programming' started by PizzaTray, Oct 31, 2009.

  1. macrumors newbie

    Joined:
    Oct 31, 2009
    #1
    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:

    Code:
    
    
    #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
     .
    	[B][COLOR="Blue"][monst initMonst][/COLOR][/B]; [B]can't call the method -initMonst[/B]
     .
     .
    }
    
    - (void)mainGameLoop {
    .
    . 
    }
    
    - (void)updateScene:(float)delta {
    .
    .
    }
    
    - (void)renderScene {
    .
    . gl bla bla
    .		
    	[B][COLOR="blue"][monst render];[/COLOR] can't call the method -render[/B]
    .
    .
    }
    
    - (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:

    Code:
    
    #import "Monster.h"
    
    @implementation Monster
    
    @synthesize img;
    @synthesize ssMonster;
    @synthesize anim;
    @synthesize location;
    @synthesize r;
    
    - (void) [B][COLOR="blue"]initMonst[/COLOR][/B] {
    		
    		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)[COLOR="blue"][B]render[/B][/COLOR] {
    	[self.img renderAtPoint:CGPointMake(100,100) centerOfImage:YES];
    }
    		
    - (void)dealloc {
    	[self.img release];		
    	[super dealloc];
    }
    
    @end
    
    
    what should i do?
     
  2. macrumors 6502

    Joined:
    Feb 7, 2008
    #2
    Are you creating an instance of Monster called monst anywhere?
    Something like:
    Code:
    Monster monst;
    monst = [Monster alloc];
    [monst initMonst];
    
     
  3. thread starter macrumors newbie

    Joined:
    Oct 31, 2009
    #3
    Can't belive it, i forgot the alloc X.X,
    two months of programming and i'm still "objective-c dumb".

    Thanks a lot!
     

Share This Page