basic spritebuilder and swift

54 Views Asked by At

I m trying to create a game using sprite builder and swift. In the game the player can change, for example the shoes of a baby in center of the screen and in the left of the screen there are different kinds of shoes wich the player can choose from. In spritebuilder i put 3 color nodes with names of colorNode , colornode1, centroNode. I would like to put the colornode in the position of centronode, one by one. Thanks Here there is the code i've Tried to write :

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")
1

There are 1 best solutions below

0
Luca Angeletti On

Given the provided error message

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

It looks like you just need to add an initializer with 0 params to your class

init () {
    // init your properties here    
}