Try the following:
-(void)draw
{
static float i = 0;
glPushMatrix();
glRotatef(i, 1.0f, 0.0f, 0.0f);
[sprite visit];
glPopMatrix();
glPushMatrix();
glRotatef(i, 0.0f, 1.0f, 0.0f);
[sprite2 visit];
glPopMatrix();
// angle x y z
if(i++ > 360) i = 0;
}
- (void)addSprites
{
CGSize s = [CCDirector sharedDirector].winSize;
// First Sprite will be rotated about the X-axis
sprite = [[CCSprite spriteWithFile:@"streak.png"] retain];
[sprite setColor:ccRED];
[sprite setPosition:ccp(s.width/2, s.height/2)];
// Second Sprite will be rotated about the Y-axis
sprite2 = [[CCSprite spriteWithFile:@"streak.png"] retain];
[sprite2 setColor:ccGREEN];
[sprite2 setPosition:ccp(s.width/2, s.height/2)];
}
-(void)dealloc
{
[sprite release];
[sprite2 release];
[super dealloc];
}
You'll also have to add
CCSprite *sprite;
CCSprite *sprite2;
as member variables of your class.
You can create your sprites as usual, except now that we're going to take control of them we have to do two things:
a) retain them so they are ours, which also means we need to release them in the dealloc
and
b) because we will be doing OpenGL modifications to them, we will not be adding them as a child.
If we were to add them as a child, we'd see two copies: The original one we added as a child that Cocos2D is controlling and the second copy from our own rotational modifications to the sprite. As we want to take control of the sprite manually, we will be drawing it via the visit method ourselves.
Last but not least we are doing all of the drawing in the draw method of our layer. This is the method that OpenGL will be active in. Doing OpenGL outside of the draw method is pointless as it won't have any affect, as you've seen.
In the demo above I simply rotate the two sprites, sprite and sprite2, in a circle about the X and Y axis respectively. They are both colored so you can easily see which is which.
Good luck!
-robodude666