drawing cocos2d v3 no longer has ccDraw* functions, how do I draw without making nodes?(绘制 cocos2d v3 不再有 ccDraw* 功能,不制作节点如何绘制?)
问题描述
我按照 http://www.cocos2d-swift.org/get-started 上的说明进行操作
并通过 Sprite Builder 创建了一个新项目.
and made a new Project through Sprite Builder.
搜索 ccDraw 没有显示任何内容.我在论坛上找到了这个例子,并实现了,但它看起来不正确.我不想要一个对资源征税的drawNode.我想要 ccDrawLine 过去如何工作的低级 GL 绘图线.当我做这样的 drawNode 时——它不会重置旧的绘图——所以我画的所有线条都留在屏幕上.
searching for ccDraw doesn't show anything. I found this example on a forum, and implemented, but it doesn't look right. I don't want a drawNode that taxes resources. I want low level GL drawing line how ccDrawLine used to work. When I do a drawNode like this -- it doesn't reset the old drawing -- so all lines I draw stay on the screen.
如何像在 v2.x 中一样进行绘制?(ccDrawLine, ccDrawCircle, ccDrawPoly)
How do I draw like in v2.x? (ccDrawLine, ccDrawCircle, ccDrawPoly)
#import "MainScene.h"
@implementation MainScene
- (id)init {
self = [super init];
_line01 = [CCDrawNode node];
[self addChild:_line01];
[self schedule:@selector(pulse) interval:0.016];
return self;
}
- (void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform {
[_line01 drawSegmentFrom:ccp(50, 50) to:ccp(x, y) radius:2 color:[CCColor colorWithRed:128 green:25/255 blue:3]];
}
- (void)pulse {
x+= 1;
y+= 3;
if (x > 500) {
x = 0;
} else if (y > 500) {
y = 0;
}
}
@end
http://www.cocos2d-swift.org/docs/api/Classes/CCDrawNode.html 建议使用 CCDrawNode 效率不高.
http://www.cocos2d-swift.org/docs/api/Classes/CCDrawNode.html suggests using a CCDrawNode is not efficient.
推荐答案
简单修改pulse如下,去掉draw
覆盖.
simply modify pulse slightly as follows, and get rid of the draw
override.
- (void)pulse {
x+= 1;
y+= 3;
if (x > 500) {
x = 0;
} else if (y > 500) {
y = 0;
}
// update the line segment
[_line01 clear];
[_line01 drawSegmentFrom:ccp(50, 50) to:ccp(x, y) radius:2 color:[CCColor colorWithRed:128 green:25/255 blue:3]];
}
这篇关于绘制 cocos2d v3 不再有 ccDraw* 功能,不制作节点如何绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:绘制 cocos2d v3 不再有 ccDraw* 功能,不制作节点如何绘制?
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01