复制代码
- void CCSprite::render(float x, float y, float angle, float xScale, float yScale)
- {
- y = SCREEN_HEIGHT-y; // for OpenGL ES, (0,0) is at lower left corner!
-
- GLfloat _minU = mX/mTexture->getTextureWidth();
- GLfloat _maxU = (mX+mWidth)/mTexture->getTextureWidth();
- GLfloat _minV = mY/mTexture->getTextureHeight();
- GLfloat _maxV = (mY+mHeight)/mTexture->getTextureHeight();
-
- GLfloat coordinates[] =
- {
- _minU, _maxV,
- _maxU, _maxV,
- _minU, _minV,
- _maxU, _minV
- };
-
- GLfloat xx = - mWidth/2;
- GLfloat yy = - mHeight/2;
-
- GLfloat vertices[] =
- {
- xx, yy,
- xx+mWidth, yy,
- xx, yy+mHeight,
- xx+mWidth, yy+mHeight
- };
-
- mTexture->bind();
-
- glColor4f(mRed, mGreen, mBlue, mAlpha);
-
- glPushMatrix();
- glTranslatef(x, y, 0.0f);
- glRotatef(angle, 0.0f, 0.0f, 1.0f);
- glScalef(xScale, yScale, 1.0f);
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glPopMatrix();
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-
- }
|