Cocos2d iPhone - Sprite cliping/mask/frame

后端 未结 3 2092
故里飘歌
故里飘歌 2020-12-01 08:38

how can i clip/crop/mask or just set the frame of a CCSprite in Cocos2D?

Something similar to: setting the frame for UIView, with clipping subviews = TRUE

My

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 09:08

    I ended up using GL_SCISSOR.

    in MainSprite I impemented:

    - (void) visit
    {
        if (!self.visible) {
            return;
        }
        glEnable(GL_SCISSOR_TEST);
        glScissor(x, y, width, height);   
        [super visit];
        glDisable(GL_SCISSOR_TEST);
    }
    

    This will clip or mask the specified area.

    The only tricky bit is that in Landscape mode Cocos2D has 0,0 at the bottom-left side of the screen, while OpenGL has it at the bottom-right corner as it doesn't consider the orientation of the screen.

    In other words, for OpenGL consider you have a rotated portrait Screen.

提交回复
热议问题