相机移动我的角色

时间:2015-02-04 13:52:04

标签: swift camera sprite-kit character

我有一个我正在研究的小项目,而且我是一个完全的初学者。我需要一些帮助,以便我能够实现一个可以跟随" char"周围。提前致谢。

如果你可以指出我正确的方向,我在哪里添加代码。那将是非常棒的,因为我查看了一些教程,并没有真正知道在哪里放置一些代码。

class GameScene: SKScene {


var char = SKSpriteNode()
var bg = SKSpriteNode()
var platform = SKSpriteNode()

override func didMoveToView(view: SKView) {
    /* Setup your scene here */

    var bgTexture = SKTexture(imageNamed: "img/bg.png")
    bg = SKSpriteNode(texture: bgTexture)
    bg.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
    bg.size.height = self.frame.height

    self.addChild(bg)

    var charTexture = SKTexture(imageNamed: "img/char.png")

    char = SKSpriteNode(texture: charTexture)
    char.position = CGPoint(x:CGRectGetMidX(self.frame), y: 900)

    char.physicsBody = SKPhysicsBody(circleOfRadius: char.size.height / 2)
    char.physicsBody!.dynamic = true

    self.addChild(char)

    var platformTexture = SKTexture(imageNamed: "img/platform.png")

    platform = SKSpriteNode(texture: platformTexture)
    platform.position = CGPoint(x:CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
    platform.physicsBody = SKPhysicsBody(rectangleOfSize: platform.size)
    platform.physicsBody!.dynamic = false

    self.addChild(platform)


    var wall = SKNode()
    wall.position = CGPointMake(0,0)
    wall.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(1, self.frame.size.height))
    wall.physicsBody!.dynamic = false

    self.addChild(wall)

    var ground = SKNode()
    ground.position = CGPointMake(0, 0)
    ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.frame.size.width, 1))
    ground.physicsBody!.dynamic = false

    self.addChild(ground)



}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */
    char.physicsBody?.velocity = CGVectorMake(0,0)
    char.physicsBody?.applyImpulse(CGVectorMake(3, 0))

}

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}

0 个答案:

没有答案