Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift语法错误:Type';任何对象';不能隐式地向下转换_Swift_Cocos2d Iphone_Cocos2d Swift - Fatal编程技术网

Swift语法错误:Type';任何对象';不能隐式地向下转换

Swift语法错误:Type';任何对象';不能隐式地向下转换,swift,cocos2d-iphone,cocos2d-swift,Swift,Cocos2d Iphone,Cocos2d Swift,我使用下面的代码在swift中创建sprite var bg : CCSprite = CCSprite.spriteWithImageNamed("Default.png"); bg.position = ccp(SW*0.5, SH*0.5) self.addChild(bg) 请检查图片,第一行有错误 错误:类型“AnyObject”不能隐式向下转换为“CCNode”:是否要使用“as”强制向下转换 网上有Cocos2d Swift文档吗?请重新编写 var bg

我使用下面的代码在swift中创建sprite

    var bg : CCSprite = CCSprite.spriteWithImageNamed("Default.png");
    bg.position = ccp(SW*0.5, SH*0.5)
    self.addChild(bg)
请检查图片,第一行有错误

错误:类型“AnyObject”不能隐式向下转换为“CCNode”:是否要使用“as”强制向下转换

网上有Cocos2d Swift文档吗?

请重新编写

var bg : CCSprite = CCSprite.spriteWithImageNamed("Default.png")
作为

Swift不会隐式转换(在本例中:
AnyObject!
CCSprite
), 您必须使用
as
添加显式强制转换

var bg = CCSprite.spriteWithImageNamed("Default.png") as CCSprite