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* 功能,不制作节点如何绘制?
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01