1

我的滑动菜单网格的点指示器有一个访问方法。

- (void) visit
{
    [super visit];//< Will draw after glPopScene.

    BOOL showPagesIndicator = YES;


    ccColor4B pagesIndicatorNormalColor_ = ccc4([sud integerForKey:key_int_r], [sud integerForKey:key_int_g], [sud integerForKey:key_int_b], 255);
    ccColor4B pagesIndicatorSelectedColor_ = ccc4(255, 255, 255, 255);
    if (showPagesIndicator)
    {
        int totalScreens = iPageCount;

        // Prepare Points Array
        CGFloat n = (CGFloat)totalScreens; //< Total points count in CGFloat.
        CGFloat pY = pageIndicatorPosition.y; //< Points y-coord in parent coord sys.
        CGFloat d = may_double(16.0f); //< Distance between points.
        CGPoint points[totalScreens];
        for (int i=0; i < totalScreens; ++i)
        {
            CGFloat pX = pageIndicatorPosition.x + d * ( (CGFloat)i - 0.5f*(n-1.0f) );
            points[i] = ccp (pX, pY);
        }

        // Set GL Values
#if COCOS2D_VERSION >= 0x00020000
//        ccGLEnable(CC_GL_BLEND);
        ccPointSize( may_double(6.0 * CC_CONTENT_SCALE_FACTOR()) );
#define DRAW_4B_FUNC ccDrawColor4B

#else
        glEnable(GL_POINT_SMOOTH);
        GLboolean blendWasEnabled = glIsEnabled( GL_BLEND );
        glEnable(GL_BLEND);

        // save the old blending functions
        int blend_src = 0;
        int blend_dst = 0;
        glGetIntegerv( GL_BLEND_SRC, &blend_src );
        glGetIntegerv( GL_BLEND_DST, &blend_dst );
        glPointSize( may_double(6.0 * CC_CONTENT_SCALE_FACTOR()) );

#define DRAW_4B_FUNC glColor4ub

#endif
        ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


        // Draw Gray Points
        DRAW_4B_FUNC(pagesIndicatorNormalColor_.r,
                     pagesIndicatorNormalColor_.g,
                     pagesIndicatorNormalColor_.b,
                     pagesIndicatorNormalColor_.a);

        ccDrawPoints( points, totalScreens );

        // Draw White Point for Selected Page
        DRAW_4B_FUNC(pagesIndicatorSelectedColor_.r,
                     pagesIndicatorSelectedColor_.g,
                     pagesIndicatorSelectedColor_.b,
                     pagesIndicatorSelectedColor_.a);
        ccDrawPoint(points[iCurrentPage]);

        // Restore GL Values
#if COCOS2D_VERSION >= 0x00020000
        ccPointSize(1.0f);
#else
        glPointSize(1.0f);
        glDisable(GL_POINT_SMOOTH);
        if (! blendWasEnabled)
            glDisable(GL_BLEND);

        // always restore the blending functions too
        ccGLBlendFunc( blend_src, blend_dst);
//        glBlendFunc( blend_src, blend_dst );
#endif
    }
}

它适用于我早期的项目,但不适用于 cocos2d v3。对于几乎每个 openGL 语句,例如glPointSize/ccPointSizeand ,我都会收到错误(对 C99 等无效) glColor4ub。我曾尝试使用 CCDrawNode(OOP 方式),但它仍然不是一对一的翻译。(glGetIntegerv等)

以下链接是我创建的测试项目(有错误,注意屏幕不可滚动,点指示器不显示(即visit功能不工作)

https://drive.google.com/file/d/0BzH5x38rukpYaVlWdUJPWW9EYWc/edit?usp=sharing

编辑:我尝试使用 [renderer enqueueMethod:@selector(drawDotIndicators) target:self];访问代码并将其放入drawDotIndicators方法中。它也不起作用

(本教程结束:https ://www.makegameswith.us/docs/#!/cocos2d/1.1/customrendering )

4

0 回答 0