Created
September 20, 2012 17:08
-
-
Save jquave/3757103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(CCRenderTexture*) createStroke: (CCLabelTTF*) label size:(float)size color:(ccColor3B)cor | |
{ | |
CCRenderTexture* rt = [CCRenderTexture renderTextureWithWidth:label.texture.contentSize.width+size*2 height:label.texture.contentSize.height+size*2]; | |
CGPoint originalPos = [label position]; | |
ccColor3B originalColor = [label color]; | |
BOOL originalVisibility = [label visible]; | |
[label setColor:cor]; | |
[label setVisible:YES]; | |
ccBlendFunc originalBlend = [label blendFunc]; | |
[label setBlendFunc:(ccBlendFunc) { GL_SRC_ALPHA, GL_ONE }]; | |
CGPoint bottomLeft = ccp(label.texture.contentSize.width * label.anchorPoint.x + size, label.texture.contentSize.height * label.anchorPoint.y + size); | |
//CGPoint positionOffset = ccp(label.texture.contentSize.width * label.anchorPoint.x - label.texture.contentSize.width/2,label.texture.contentSize.height * label.anchorPoint.y - label.texture.contentSize.height/2); | |
//use this for adding stoke to its self... | |
CGPoint positionOffset= ccp(-label.contentSize.width/2,-label.contentSize.height/2); | |
CGPoint position = ccpSub(originalPos, positionOffset); | |
[rt begin]; | |
for (int i=0; i<360; i+=30) // you should optimize that for your needs | |
{ | |
[label setPosition:ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*size, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*size)]; | |
[label visit]; | |
} | |
[rt end]; | |
[label setPosition:originalPos]; | |
[label setColor:originalColor]; | |
[label setBlendFunc:originalBlend]; | |
[label setVisible:originalVisibility]; | |
[rt setPosition:position]; | |
return rt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment