我正试图在游戏中心报道我的高分.我认为我的代码正在运行,但游戏中心没有使用高分进行更新.排行榜创建时使用此参考名称:"funfairBalloon"和此排行榜ID:55009943.我有3个沙盒测试人员,游戏中心启用,玩家在游戏中心进行身份验证.
我的身份验证和报告代码是:
func authenticateLocalPlayer()
{
var localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler =
{ (viewController : UIViewController!, error : NSError!) -> Void in
if viewController != nil
{
self.presentViewController(viewController, animated:true, completion: nil)
}
else
{
if GKLocalPlayer.localPlayer().authenticated {
let gkScore = GKScore(leaderboardIdentifier: "55009943")
gkScore.value = Int64(highscore)
GKScore.reportScores([gkScore], withCompletionHandler: {(error) -> Void in
let alert = UIAlertView(title: "Success",
message: "Score updated",
delegate: self,
cancelButtonTitle: "Ok")
alert.show()
})
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
你有好主意吗?
我成功地使用以下代码暂停场景游戏:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
var touch:UITouch = touches.anyObject() as UITouch
pauseText.text = "Continuer"
pauseText.fontSize = 50
pauseText.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2)
/* bouton play/pause */
var locationPause: CGPoint = touch.locationInNode(self)
if self.nodeAtPoint(locationPause) == self.pause {
println("pause")
addChild(pauseText)
pause.removeFromParent()
paused = true
}
if self.nodeAtPoint(locationPause) == self.pauseText {
pauseText.removeFromParent()
paused = false
addChild(pause)
}
}
Run Code Online (Sandbox Code Playgroud)
但我有一个问题.游戏的所有随机间隔创建对象并在屏幕上显示它们.当我暂停游戏时,它继续在后台创建对象,当我恢复游戏时,暂停期间创建的所有对象同时出现在屏幕上.
我该如何解决?
我的游戏应该在60年代后停止.但我的计时器代码没有任何反应.
var timer = NSTimer()
var counter:Int = 60
var labelCounter:SKLabelNode = SKLabelNode()
Run Code Online (Sandbox Code Playgroud)
这是我的GameScene类中的代码:
func startTimer()
{
timer = NSTimer.scheduledTimerWithTimeInterval(1.0
, target: self, selector: Selector("updateTimer:"), userInfo: nil, repeats: true)
}
func updateTimer(dt:NSTimer)
{
counter--
if counter == 0 {
timer.invalidate()
removeCountDownTimerView()
} else{
labelCounter.text = "\(counter)"
}
}
func removeCountDownTimerView()
{
scene.view.paused = true
}
Run Code Online (Sandbox Code Playgroud)
感谢您的见解 :-)
我正在 Iphone 和 Ipad 上开发游戏,就像太空入侵者一样。
要摧毁的气球从屏幕顶部直线落下。
这是我添加它们的代码:
func addBalloonv(){
var balloonv:SKSpriteNode = SKSpriteNode (imageNamed: "ballonvert.png")
balloonv.physicsBody = SKPhysicsBody (circleOfRadius: balloonv.size.width/2)
balloonv.physicsBody.dynamic = true
balloonv.physicsBody.categoryBitMask = balloonCategory | greenCategory
balloonv.physicsBody.contactTestBitMask = flechetteCategory
balloonv.physicsBody.collisionBitMask = balloonCategory
balloonv.physicsBody.mass = 1
balloonv.physicsBody.restitution = 1
balloonv.physicsBody.allowsRotation = true
let minX = balloonv.size.width/2
let maxX = self.frame.size.width - balloonv.size.width/2
let rangeX = maxX - minX
let position:CGFloat = CGFloat(arc4random()) % CGFloat(rangeX) + CGFloat(minX)
balloonv.position = CGPointMake(position, self.frame.size.height+balloonv.size.height)
self.addChild(balloonv)
Run Code Online (Sandbox Code Playgroud)
我有一个气球颜色的功能。
所以目前它们直线移动,我正在寻找从顶部和两侧的随机运动(像空气中的气球一样的湍流)。
我怎样才能做到这一点?
非常感谢 !!
我想删除屏幕外的所有对象.目前我使用带有"障碍"的接触检测.
我初始化屏幕周围的障碍,当SpriteNode与其中一个接触时,它将从场景中删除.但是这种方法不能很好地工作并使我的游戏崩溃.
你知道是否有一种简单的方法可以从屏幕上删除所有对象吗?
这里我的代码有障碍:
// declarations
var barrierLeft:SKSpriteNode = SKSpriteNode()
var barrierRight:SKSpriteNode = SKSpriteNode()
var barrierTop:SKSpriteNode = SKSpriteNode()
// In didMoveToView method
barrierLeft.size = CGSizeMake(1, self.frame.height*2)
barrierLeft.physicsBody = SKPhysicsBody (rectangleOfSize: barrierLeft.size)
barrierRight.position = CGPointMake(0, 0)
barrierLeft.physicsBody?.dynamic = false
barrierLeft.physicsBody?.categoryBitMask = barrierCategory
barrierLeft.physicsBody?.contactTestBitMask = flechetteCategory
addChild(barrierLeft)
barrierRight.size = CGSizeMake(1, self.frame.height*2)
barrierRight.physicsBody = SKPhysicsBody (rectangleOfSize: barrierLeft.size)
barrierRight.position = CGPointMake(self.size.width+10, 0)
barrierRight.physicsBody?.dynamic = false
barrierRight.physicsBody?.categoryBitMask = barrierCategory
barrierRight.physicsBody?.contactTestBitMask = flechetteCategory
addChild(barrierRight)
//
func didBeginContact(contact: SKPhysicsContact!)
{
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
if …Run Code Online (Sandbox Code Playgroud)