Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 如何使SKLabelNode成为在SpriteKit中显示新视图的元素? class游戏场景:SKScene{ 类LabelButton:SKLabelNode{ 覆盖函数touchesend(touchs:Set,带有事件:UIEvent?){ 用于触摸:触摸中的任何对象{ 让位置=接触点(位置) 如果self.contains(位置){ 打印(“无”) } } } } 覆盖func didMove(到视图:SKView){ let nothing=LabelButton(名称:“旧金山”) nothing.text=“什么都没有?” nothing.fontColor=SKColor.white nothing.fontSize=20 nothing.position=CGPoint(x:200,y:200) addChild(无) } func goToPlanetNothing(){ var gameScene1=PlanetNothing0(文件名为:“PlanetNothing0”) 让过渡生效= SKTransition.flipHorizontal(持续时间:1.0) 游戏场景1=PlanetNothing0(大小:(游戏场景1?.size)!) 游戏场景1?.anchorPoint=CGPoint(x:0.0,y:0.0) gameScene1?.view?.presentScene(gameScene1!,过渡:过渡效果) }_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios 如何使SKLabelNode成为在SpriteKit中显示新视图的元素? class游戏场景:SKScene{ 类LabelButton:SKLabelNode{ 覆盖函数touchesend(touchs:Set,带有事件:UIEvent?){ 用于触摸:触摸中的任何对象{ 让位置=接触点(位置) 如果self.contains(位置){ 打印(“无”) } } } } 覆盖func didMove(到视图:SKView){ let nothing=LabelButton(名称:“旧金山”) nothing.text=“什么都没有?” nothing.fontColor=SKColor.white nothing.fontSize=20 nothing.position=CGPoint(x:200,y:200) addChild(无) } func goToPlanetNothing(){ var gameScene1=PlanetNothing0(文件名为:“PlanetNothing0”) 让过渡生效= SKTransition.flipHorizontal(持续时间:1.0) 游戏场景1=PlanetNothing0(大小:(游戏场景1?.size)!) 游戏场景1?.anchorPoint=CGPoint(x:0.0,y:0.0) gameScene1?.view?.presentScene(gameScene1!,过渡:过渡效果) }

Ios 如何使SKLabelNode成为在SpriteKit中显示新视图的元素? class游戏场景:SKScene{ 类LabelButton:SKLabelNode{ 覆盖函数touchesend(touchs:Set,带有事件:UIEvent?){ 用于触摸:触摸中的任何对象{ 让位置=接触点(位置) 如果self.contains(位置){ 打印(“无”) } } } } 覆盖func didMove(到视图:SKView){ let nothing=LabelButton(名称:“旧金山”) nothing.text=“什么都没有?” nothing.fontColor=SKColor.white nothing.fontSize=20 nothing.position=CGPoint(x:200,y:200) addChild(无) } func goToPlanetNothing(){ var gameScene1=PlanetNothing0(文件名为:“PlanetNothing0”) 让过渡生效= SKTransition.flipHorizontal(持续时间:1.0) 游戏场景1=PlanetNothing0(大小:(游戏场景1?.size)!) 游戏场景1?.anchorPoint=CGPoint(x:0.0,y:0.0) gameScene1?.view?.presentScene(gameScene1!,过渡:过渡效果) },ios,swift,sprite-kit,Ios,Swift,Sprite Kit,这是代码。如果我转到模拟器,我单击该元素,但什么也没有发生。但是,代码不会崩溃或显示错误。在touchesend()内尝试此操作。: 仅供参考,你不想打印(“无”)然后说什么也没发生。你是说你什么也没打印,还是说什么都没打印。我用的是打印(“无”)作为占位符。我尝试了你的答案@Christoph,但标签现在根本没有显示出来。@MadelineCoven我建议你提高解决问题的能力。看看Christoph提供的代码。代码不会导致标签消失。这意味着你做了一些超出Christoph可以看到的范围的事情。

这是代码。如果我转到模拟器,我单击该元素,但什么也没有发生。但是,代码不会崩溃或显示错误。

touchesend()内尝试此操作。


仅供参考,你不想打印(“无”)然后说什么也没发生。你是说你什么也没打印,还是说什么都没打印。我用的是打印(“无”)作为占位符。我尝试了你的答案@Christoph,但标签现在根本没有显示出来。@MadelineCoven我建议你提高解决问题的能力。看看Christoph提供的代码。代码不会导致标签消失。这意味着你做了一些超出Christoph可以看到的范围的事情。我支持的代码vided surly不会使标签消失,因此您的代码中一定有其他内容发生了更改。@Christoph我重新排列了类和函数以使其正常工作。那么它现在是否正常工作了?
class GameScene: SKScene {
class LabelButton: SKLabelNode {
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch: AnyObject in touches {
            let location = touch.atPoint(position)
            if self.contains(location) {
                print ("nothing")
            }
        }
    }
}



override func didMove(to view: SKView) {
    let nothing = LabelButton(fontNamed: "San Francisco")
    nothing.text = "nothing?"
    nothing.fontColor = SKColor.white
    nothing.fontSize = 20
    nothing.position = CGPoint(x: 200, y: 200)
    addChild(nothing)
}

func goToPlanetNothing(){
    var gameScene1 = PlanetNothing0(fileNamed: "PlanetNothing0")


    let transitionEffect =
        SKTransition.flipHorizontal(withDuration: 1.0)
    gameScene1 = PlanetNothing0(size: (gameScene1?.size)!)
    gameScene1?.anchorPoint = CGPoint(x: 0.0, y: 0.0)
    gameScene1?.view?.presentScene(gameScene1! , transition:transitionEffect)
}
for touch in touches {
    if self.contains(touch.location(in: self.scene!)) {
        print("nothing")
    }
}