请问creator环境下如何实现截屏?

我本来打算用下面的代码来实现的。

代码:


var renderTexture=cc.RenderTexture.create(720,1280,1,0);

renderTexture.begin();
this.node.visit();
renderTexture.end();

模拟器下报错:

Simulator : cocos2d: Texture2D: Error uploading compressed texture level: 0 . glError: 0x0500
Simulator : Assert failed: Could not attach texture to framebuffer
Simulator : Assertion failed: (glCheckFramebufferStatus(0x8D40) == 0x8CD5), function initWithWidthAndHeight, file /Users/nantas/fireball-x/fbnew-build/cocos2d-x/cocos/2d/CCRenderTexture.cpp, line 269.

浏览器下报错:

Uncaught TypeError: this.node.visit is not a function

因为没有creator的node没有visit这个方法,所以,请问creator环境下如何截屏?

每日一顶,求解答

目前的官方 API 还不支持

一个 hack 一点的方法

renderTexture.begin();
this.node._sgNode.visit();
renderTexture.end();

代码如下

var renderTexture = cc.RenderTexture.create(599,599);
renderTexture.begin();
this.node._sgNode.visit();
renderTexture.end();
this.node.addChild( renderTexture , 9999 );

浏览器报错:

this._parent.reorderChild is not a function

模拟器报错:

Simulator : jsb: ERROR: File /Users/nantas/fireball-x/fbnew-build/cocos2d-x/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp: Line: 2944, Function: js_cocos2dx_Node_setParent
Simulator : Invalid Native Object
Simulator : /Applications/@DevelopeTools/CocosCreator.app/Contents/Resources/app.asar.unpacked/utils/simulator/mac/Simulator.app/Contents/Resources/src/jsb_polyfill.js:16988:Error: Invalid Native Object

看样子似乎是addChild的时候出错了,因为不需要saveToFile保存到本地再读取进来,所以请问我要怎么才能把这张截图直接显示到当前场景?

求解决求解决

this.node._sgNode.addChild( renderTexture , 9999 );

那保存到本地的代码怎么写

renderTexture. saveToFile"demo.png"),“PNG”);
这样?

我如果需要saveToFile保存到本地 怎么做呢?

那你截图可以截吗?我截出来是一片惨白…

现在截图还是就这一种方法吗?
两个问题:1.如果要截图的node在屏幕外,截图是白色的,什么也没有;
2.对于半透明图的截图,显示的和屏幕的样子不一样,半透明图会变白

用 this.node._sgNode.addChild( renderTexture , 9999 );接下来如何 保存本地呢,浏览器,大佬。

对啊,怎么保存

保存需要,修改路径