在雪碧套件Xcode愤怒的小鸟弹弓

时间:2015-11-05 01:09:06

标签: swift sprite-kit

我正在使用精灵套件在Xcode上制作一个游戏,我需要添加一个像球一样的愤怒的小鸟弹弓,我不知道如何应用它

import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {let sprite = SKSpriteNode(imageNamed:"ball")
    sprite.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
    sprite.physicsBody = SKPhysicsBody(circleOfRadius: 20)
    sprite.size.height = 50
    sprite.size.width = 50
    sprite.physicsBody?.affectedByGravity = true
    sprite.physicsBody!.allowsRotation = false
    sprite.physicsBody!.friction = 0
    sprite.physicsBody!.restitution = 1
    sprite.physicsBody!.linearDamping = 0
    sprite.physicsBody!.angularDamping = 0
    self.addChild(sprite)

    // 1. Create a physics body that borders the screen
    let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
    // 2. Set the friction of that physicsBody to 0
    borderBody.friction = 0
    // 3. Set physicsBody of scene to borderBody
    self.physicsBody = borderBody

1 个答案:

答案 0 :(得分:0)

只要给球一个冲动,重力将完成剩下的工作。