This is a similar to jumping Doodle small game, the protagonist constantly eat energy ball to get jumping energy to jump to a higher place, if the picture hit the black hole is hung ...
In the game debugging process if you can know in real time the height of the protagonist is good, which will help the program ape dynamic judgment game victory and defeat logic.
You can use Print to display the height in the console, but this is not very convenient to watch, simply let us put the height of the logo and the protagonist of the game to close together!;]
Because any Sknode object and its child objects in Spritekit can contain children, they can be moved with the parent node, rotated, scaled ... That's the effect we want.
First, add the following code after the code that created the game lead:
Add a label with a display height above the player let label = Sklabelnode (fontnamed:"Copperplate") label. Horizontalalignmentmode=. CenterLabel. Verticalalignmentmode=. TopLabel. Position= Cgpoint (x:0,y: Self. Size. Height/2.0+ -) label. FontSize=20.0Label. FontColor= Skcolor. Whitecolor() label. Text="\ (SELF.POSITION.Y)"Label. Name="Heightlabel"Self. AddChild(label)
One would ask why the label's position is (0,size.height/2.0 + 20.0), because its parent node anchor is in the center of the texture, i.e. (0.5,0.5), so label.position.x = 0 means the x axis is in the center position, The y-axis is located at the top of the game leading up to 20 points.
Finally we will refresh the array in real time and add the following line to the Gamescene Update method:
iflet label = playerNode!.childNodeWithName("heightLabel"as? SKLabelNode{ "\(Int(playerNode!.position.y))" }
To compile and run the app, let's look at the effect:
Spritekit Add a height marker to the game bounce character