I am using Cocos2d-iphone and want to add one red pixel to the screen. I tried creating an CCSprite but the size should only be one pixel.
I don't want to create an image file.
How to realize it?
I am using Cocos2d-iphone and want to add one red pixel to the screen. I tried creating an CCSprite but the size should only be one pixel.
I don't want to create an image file.
How to realize it?
在 Swift 中 - 与 Viktor 的答案几乎相同 - 但不是每个像素创建 1 个对象,而是每次调用CCDrawNode
时都会绘制同一个对象。CCDrawNode
drawDot
创建 _drawNode 成员变量
var _drawNode : CCDrawNode!
启动 CCDrawNode 对象
_drawNode = CCDrawNode()
self.addChild(_drawNode) // add it to the node you are currently in
// draw the dot, can be recalled anywhere in this class
let touchLocation = ccp(10,10)
_drawNode.drawDot(touchLocation, radius: 1, color: CColor.blackColor())
解决了,CCDrawNode类中有一个方法,可以画一个点:
CCDrawNode *oneRedPixelA = [[CCDrawNode alloc] init];
CGPoint positionA = CGPointMake(aLabel.contentSize.width * aLabel.anchorPoint.x, aLabel.contentSize.height * aLabel.anchorPoint.y);
[oneRedPixelA drawDot:positionA radius:3.0f color:ccc4f(1.0f, 0.0f, 0.0f, 0.5f)];
[aLabel addChild:oneRedPixelA z:500];