Cocos2D 2.x: Изпълнението на CCWave действие кара спрайта да изчезне

Мога да изпълнявам CCWave действия върху спрайтове без проблем, с изключение на този конкретен случай. Инициализирам мой клас, който има CCSprite, който добавям към CCRenderTexture. Спрайтът се прави чрез добавяне на текстури на спрайтове на плочки към CCRenderTexture и след това премахване на плочките. Мога да добавя спрайта към CCRenderTexture като дете без проблем, но ако добавя функцията CCWave и я стартирам, спрайтът изчезва.

        // 1: Create new CCRenderTexture
        CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:width height:height];

        // 2: Call CCRenderTexture:begin
        [rt beginWithClear:0 g:0 b:0 a:0];

        /* this is a loop where I get all tiles 
           within a bounding object's rectangle */

        CGPoint tileCoord;

        for(int w = 0; w < (width / tilePxWidth); ++w){

            for(int h = (height / tilePxWidth); h > 0; --h){

                tileCoord = [TileCoord tileCoordForPosition:ccp(x + (w * tilePxWidth),
                                                                y + (h * tilePxWidth))
                                                    withMap:theMap];



                CCSprite *backgroundTileSprite = [self.background tileAt:tileCoord];

                CCSprite *copiedSprite = [CCSprite spriteWithTexture:backgroundTileSprite.texture
                                                                rect:backgroundTileSprite.textureRect];

                [copiedSprite.texture setAliasTexParameters];

                copiedSprite.position = ccp(8 + (w * tilePxWidth),
                                           (8 + (h * tilePxWidth)) - 16);

                // 3: Visit to update renderTexture (rt)
                [copiedSprite visit];

                [self.background removeTileAt:tileCoord];

            }


        }


        // 4: Call CCRenderTexture:end
        [rt end];

        // 5: Create a new sprite from the texture
        waterLine.tilesSprite = [CCSprite spriteWithTexture:rt.sprite.texture];


        [theMap addChild:waterLine.tilesSprite z:[[theMap layerNamed:@"background"] zOrder]-1];

        waterLine.tilesSprite.flipY = YES;

        waterLine.tilesSprite.anchorPoint = CGPointZero;

        waterLine.tilesSprite.position = ccp(x,y);



        [waterLines insertObject:waterLine atIndex:waterLineNum];

        // if I add the code below, the sprite no longer shows up!

        id waveEffect = [CCWaves actionWithDuration:25
                                               size:CGSizeMake(1,10)
                                              waves:3
                                          amplitude:8
                                         horizontal:NO
                                           vertical:YES];

        [waterLine.tilesSprite runAction:[CCRepeatForever actionWithAction:waveEffect]];

Само няколко допълнителни подробности, които може да са ви любопитни. Имам прозрачен фон в тази игра, така че фонът може да работи отделно от играта, когато правя преходи на сцени.

Някои неща в моя делегат:

CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGBA8
                                   depthFormat:GL_DEPTH24_STENCIL8_OES
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];


[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

glView.opaque = NO;
glClearColor(0.0f,0.0f,0.0f,0.0f);

[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

person Chewie The Chorkie    schedule 10.06.2015    source източник


Отговори (1)


Току-що разбрах, че изглежда този ефект трябва да се направи върху spriteSheet, а не върху спрайт.

person Chewie The Chorkie    schedule 11.06.2015