在 Player.Swift 里面走Hero这个功能的主要功能我想停止在触摸位置行走。
此功能将在 GameScene.swift
内继续运行我希望当用户点击目标位置时停止我的英雄,但是当用户点击新目标位置时英雄停止英雄移动新位置并再次停止。
这是我的代码:
{
override init() {
let atlas = SKTextureAtlas(named: "characters")
let texture = atlas.textureNamed("player_ft1")
texture.filteringMode = .Nearest
sprite = AnimatedSprite(texture: texture)
// sprite = SKSpriteNode(texture: texture)
super.init()
addChild(sprite)
name = "player"
// 1
var minDiam = min(sprite.size.width, sprite.size.height)
minDiam = max(minDiam-16.0, 4.0)
let physicsBody = SKPhysicsBody(circleOfRadius: minDiam/2.0)
// 2
physicsBody.usesPreciseCollisionDetection = true
// 3
physicsBody.allowsRotation = false
physicsBody.restitution = 1
physicsBody.friction = 0
physicsBody.linearDamping = 0
physicsBody.collisionBitMask = PhysicsCategory.Boundary
physicsBody.collisionBitMask = PhysicsCategory.Boundary | PhysicsCategory.Wall | PhysicsCategory.Water
//physicsBody.dynamic=false
// 4
self.physicsBody = physicsBody
sprite.facingBackAnim = AnimatedSprite.createAnimWithPrifix("player",suffix: "ft")
sprite.facingForwardAnim = AnimatedSprite.createAnimWithPrifix("player",suffix: "bk")
sprite.facingSideAnim = AnimatedSprite.createAnimWithPrifix("player",suffix: "lt")
sprite.runAction(sprite.facingBackAnim)
}
func moveToward(target: CGPoint) {
// _Lastlocation
let targetVector = (target - position).normalized() * 150.0
physicsBody?.velocity = CGVector(point: targetVector)
faceCurrentDirection()
}