0
我正在嘗試在iOS應用程序的iPad應用程序中創建繪畫功能。我已經設法讓顏色通過觸摸出現,但我想重新創建photoshop的多功能性,以便底層的黑白圖像繼續顯示顏色。我開始以不透明的方式做到這一點,但是在同一個地點進行會導致它最終被移除。我正在使用cocos2d,這是示例代碼。在繪畫中創建多重效果iPad應用程序
in header
CCSprite *background;
CCRenderTexture *target;
CCSprite *brush;
in init method:
background = [CCSprite spriteWithFile:@"background.png"];
background.position = ccp(self.size.width/2, self.size.height/2);
[self addChild: background z:-1];
target = [[CCRenderTexture alloc] initWithWidth:self.size.width height:self.size.height pixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[target setPosition:ccp(self.size.width/2, self.size.height/2)];
brush = [[CCSprite spriteWithSpriteFrameName:@"brush_spot.png"] retain];
[brush setColor:ccRED];
in -(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event method:
[target begin];
[brush setPosition:<CALCULATED POSITION>];
[brush visit];
[target end];
我曾嘗試在畫筆上使用不同的混合功能,但沒有設法創建我想要的外觀。直接在背景上添加一個精靈及其混紡功能設定爲
[sprite setBlendFunc:(ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];
當我沒有得到正確的效果,但是當我嘗試使用這種混合功能上刷什麼出現在屏幕上。
感謝 伊恩
嗨Minthos,謝謝你的回覆。我嘗試了不同的選項,但是我一直無法得到這個工作。你可以提供一些示例代碼爲cocos2d來實現這一目標嗎?如果我無法實現這個目標,有什麼方法可以阻止不透明度的增加?所以如果我將不透明度設置爲100,那麼無論用戶使用了多少次,它都會保持不變。 – sparkdoo