Help
Help
- Subject: Help
- From: Denis Vaillant <email@hidden>
- Date: Fri, 12 Dec 2003 20:26:47 +0100
Hello everybody,
I am programming a little game and I have a big issue ;(
I have two classes :
- The first one, controller, is a subclass of NSObject. This class processes
the position of the players on the screen, depending of which key on the
keybord is pressed
- The second one, myOpenGLView, is a subclass of NSOpenGLView. This class
draw the players on screen, with their movements. Before drawing (with the
drawRect method of NSOpenGLView), myOpenGLView fetch the new position of
the player by calling a method of controller class. The position is given by
two int, x and y.
I have a real problem with the drawRect method of myOpenGLView : if I do an
NSLog of X and Y when this method is executed, the values are right and
correctly updated over time ( but the players do not move : like the x and
y values were null.
If I put the content of the controller class in myOpenGLView class, the
players move perfectly on screen...
Here is the code of the drawRect method. I put comments on them :
- (void) drawRect:(NSRect)rect
{
if (NO == fGLInit)
[self prepareOpenGL];
fGLInit = YES;
// fetching the last positions of the players from the controller class
bx[0] = [_movementController bx1];
bx[1] = [_movementController bx2];
by[0] = [_movementController by1];
by[1] = [_movementController by2];
// I check if the positions are correctly updated (depending of which
key has been pressed on the keybord) and they are !!!
NSLog(@"bx[0] : %i", bx[0]);
NSLog(@"bx[1] : %i", bx[1]);
NSLog(@"by[0] : %i", by[0]);
NSLog(@"by[1] : %i", by[1]);
// clear our drawable
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// going to FirstPlayer position
glTranslatef (bx[0], by[0], 0); //the translation is not done bx[0] &
by[0] were null
// drawing First Player
drawFirstPlayer(1.0f, 0.92, 0.10, 0.17);
// returning to center and going to SecondPlayer position
glTranslatef (-bx[0], -by[0], 0);
glTranslatef (bx[1], by[1], 0); //the translation is not done bx[1] &
by[1] were null
// drawing Second Player
drawSecondPlayer(1.0f, 0.52, 0.44, 0.22);
// updating openGlView
glFlush ();
}
I you have any idea why this occursn this would be fantastic ;)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.