我正在爲cocos2d-JS上的Facebook創建遊戲,其中需要共享遊戲的屏幕截圖。如何從RenderTexture獲取byteArray或base64字符串Cocos2d-JS
我能夠截取屏幕截圖,但現在無法將其上傳到Parse.com服務器,因爲它需要base64格式或字節數組。我無法找到任何將Sprite轉換爲此格式的解決方案..這裏是我的代碼,因此當我添加它的即將到來的適當的結果時。我還添加了我的已評論的代碼,以便它可以幫助理解我已經嘗試了很多事情,但不能實現相同。
shareToSocialNetworking: function() {
cc.director.setNextDeltaTimeZero(true);
var newsize = cc.director.getVisibleSize();
var renderText = new cc.RenderTexture(newsize.width,newsize.height);
renderText.begin();
cc.director.getRunningScene().visit();
renderText.end();
var result = cc.Sprite.create(renderText.getSprite().getTexture());
result.flippedY = true;
this._mainViewNode.addChild(result,6000);
//renderText.saveToFile("screenshot.jpg",cc.IMAGE_FORMAT_PNG);
//var based = renderText.getSprite().getTexture().getStringForFormat().toString();
//var data = based.getData();
var file = new Parse.File("screen.jpg", { base64: this.getBase64(result) });
//var file = new Parse.File("screen.jpg", data, "image/png");
var self = this;
file.save().then(function() {
// The file has been saved to Parse.
alert(file.url);
this.onSharePictureInfoLink(file.url());
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
});
//
//var ccImage = renderText.newCCImage();
//
//var str = ccImage.getData();
},
有沒有可以做什麼解決辦法
你可以試試這個: - https://stackoverflow.com/questions/44520608/how-to- get-sprite-pixel-alpha-information-in -cocos2d -js -c/45030826#45030826 – 2017-07-17 11:54:12
你可以試試這個: - https://stackoverflow.com/questions/44520608/how-to-get-sprite-pixel- alpha-information-in-cocos2d-js-c/45030826#45030826 – 2017-07-17 11:55:23