I'm trying to use cocos2d to take a screenshot of the current scene. Working off of this answer to a previous question, I translated it over to Swift, and got this:
func takeScreenshot() -> UIImage {
CCDirector.sharedDirector().nextDeltaTimeZero = true
let viewSize: CGSize = CCDirector.sharedDirector().viewSize()
let renderTexture: CCRenderTexture = CCRenderTexture.renderTextureWithWidth(viewSize.width, height: viewSize.height)
renderTexture.begin()
CCDirector.sharedDirector().runningScene.visit()
renderTexture.end()
return renderTexture.getUIImage()
}
However, I get a compiler error on:
let renderTexture: CCRenderTexture = CCRenderTexture.renderTextureWithWidth(viewSize.width, height: viewSize.height)
It says "cannot invoke 'renderTextureWithWidth' with an argument list of type '(CGFloat, height: CGFloat)'".
I checked the CCRenderTexture.h
file, and it says:
+(instancetype)renderTextureWithWidth:(int)w height:(int)h;
I tried type casting the viewSize.width
and the viewSize.height
to Int
, but it still gave the same "cannot invoke" error again.
Anyone know why this is the case and how it can be fixed?