gpt4 book ai didi

swift - 基本的 spritebuilder 和 swift

转载 作者:行者123 更新时间:2023-11-30 13:42:07 24 4
gpt4 key购买 nike

我正在尝试使用 sprite builder 和 swift 创建一个游戏。在游戏中玩家可以改变,例如屏幕中央是婴儿的鞋子,而屏幕左侧有不同种类的鞋子供玩家选择。在 spritebuilder 中,我放置了 3 个颜色节点,名称分别为 colorNode 、 colornode1 、 centroNode 。我想将colornode一一放在centronode的位置。谢谢这是我尝试编写的代码:

class MainScene: CCNode {

let colorNode : CCNodeColor!
let colorNode1 : CCNodeColor!
weak var centroNode : CCNodeColor!

init (centroNode:CCNodeColor){
self.centroNode=centroNode

}

override func onEnter() {
super.onEnter()
self.userInteractionEnabled = true
}

override func touchBegan(touch: CCTouch!, withEvent event: CCTouchEvent!) {


let touchPosition = touch.locationInNode(self)

if(CGRectContainsPoint(colorNode.boundingBox(), touchPosition))

{
print("entratooo")
centroNode=colorNode
print("centroooo")

let move = CCActionMoveTo(duration:1.0, position:ccp(20, 100))
centroNode.runAction(move)



}

else {print ("toccooo")}

if(CGRectContainsPoint(colorNode1.boundingBox(), touchPosition))


{
print("entratooo22")

最佳答案

鉴于提供的错误消息

MIOGIOCO43.spritebuilder/Source/MainScene.swift: 3: 7: fatal error: use of unimplemented initializer 'init()' for class 'MIOGIOCO43.MainScene' (lldb)

看起来你只需要向你的类添加一个带有 0 个参数的初始化器

init () {
// init your properties here
}

关于swift - 基本的 spritebuilder 和 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35434577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com