最近,一位朋友通过FB Messenger发送了一个篮球比赛,我认为这是一个非常酷的游戏。我想重新创造它只是为了好玩。
你滑到"拍摄"球进入球门。简单。目标是1-10分的固定目标。从11-20分左右移动。从21-30分开后,从左到右移动得快一点。另一位朋友说,目标曲折在屏幕上以31分排出。我的最高分是22.球也随机地沿着屏幕底部的x轴在五个不同的位置移动。
我能够让目标向左或向右移动但不是重复动作。
我正在使用Xcode 7.3和Swift 2.2。任何帮助,将不胜感激。只是想确保我朝着正确的方向前进。
GameScene.swift
let ball = SKSpriteNode(imageNamed: "basketball")
var gameScore: SKLabelNode!
var score: Int = 0 {
didSet {
gameScore.text = "Score: \(score)"
}
}
override func didMoveToView(view: SKView) {
/* Setup your scene here */
self.backgroundColor = SKColor.whiteColor()
// Sets the game score BUT it is not displaying on the screen.
gameScore = SKLabelNode(fontNamed: "Chalkduster")
gameScore.text = "Score: 0"
gameScore.position = CGPoint(x: 250, y: 500)
gameScore.horizontalAlignmentMode = .Left
gameScore.fontSize = 20
addChild(gameScore)
score = 0
// Create Physics Body that borders the bottom of the screen
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
// Set friction to 0
borderBody.friction = 0
// Set physicsBody to borderBody
self.physicsBody = borderBody
// Add the ball to the scene
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.width / 2.0)
ball.physicsBody!.restitution = 0.4
ball.xScale = 0.2
ball.yScale = 0.2
ball.position = CGPoint(x: CGRectGetMidX(self.frame), y: 0)
ball.name = "ball"
addChild(ball)
// Commented out so the goal can be stationary
// moveGoal()
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)
{
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
/* Called when a touch begins */
}
func moveGoal()
{
let movingGoal = SKSpriteNode(imageNamed: "Goal")
movingGoal.position = CGPoint(x: CGRectGetMidX(self.frame), y: 525)
movingGoal.xScale = 0.7
movingGoal.yScale = 0.7
movingGoal.runAction(SKAction.moveByX(size.width, y: 0.0, duration: 5.0))
addChild(movingGoal)
}
func moveBallAlongXAxis()
{
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.width / 2.0)
ball.physicsBody!.restitution = 0.4
ball.xScale = 0.2
ball.yScale = 0.2
ball.position = CGPoint(x: CGRectGetMidX(self.frame), y: 25)
ball.name = "ball"
addChild(ball)
}
override func update(currentTime: CFTimeInterval)
{
}