I'am using SwipeGesture to move the car Up & Down. The car is not moving when I added the below line(physicsbody):
playerCar.physicsBody = SKPhysicsBody(rectangleOfSize: playerCar.frame.size)
Note: project is running fine without that line
**I need physicsBody to complete the game
import SpriteKit
class GameScene: SKScene,SKPhysicsContactDelegate {
var playerCar = SKSpriteNode()
var swipeUp = UIGestureRecognizer()
var swipeDn = UIGestureRecognizer()
override func didMoveToView(view: SKView) {
//Car
let playerCarTexture = SKTexture(imageNamed: "playerCar.png")
playerCar = SKSpriteNode(texture: playerCarTexture)
playerCar.position = CGPoint(x:frame.size.width/2, y: frame.size.height/2)
playerCar.physicsBody = SKPhysicsBody(rectangleOfSize: playerCar.frame.size)
playerCar.physicsBody?.dynamic = true
playerCar.physicsBody?.affectedByGravity = false
playerCar.physicsBody?.allowsRotation = false
self.addChild(playerCar)
//Swipe
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipeUpFunc:"))
swipeUp.direction = .Up
view.addGestureRecognizer(swipeUp)
let swipeDn:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipeDnFunc:"))
swipeDn.direction = .Down
view.addGestureRecognizer(swipeDn)
}
func swipeUpFunc(sender:UISwipeGestureRecognizer){
if playerCar.position.y == (frame.size.height/2)
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: (frame.size.height/2) + 30)
}
else if playerCar.position.y == (frame.size.height/2) + 30
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: (frame.size.height/2) + 60)
}
else if playerCar.position.y == (frame.size.height/2) + 60
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: (frame.size.height/2) + 90)
}
}
func swipeDnFunc(sender:UISwipeGestureRecognizer){
if playerCar.position.y == (frame.size.height/2) + 90
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: (frame.size.height/2) + 60)
}
else if playerCar.position.y == (frame.size.height/2) + 60
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: (frame.size.height/2) + 30)
}
else if playerCar.position.y == (frame.size.height/2) + 30
{
self.playerCar.position = CGPoint(x:frame.size.width/2, y: frame.size.height/2)
}
}
}