请原谅命名约定以及我在代码中缩进和创建新空格的方式我知道这不正常但我很奇怪D:
无论如何,我将恢复原状设置为1并且似乎没有工作,所以我甚至尝试了1.0,看看我是否必须这样做而且它不起作用。通过它,我指的是从边界/框架反弹的物体。
我不能做CGVectorMake,因为我使用的swift不允许它。任何人都有任何有用的提示?
我唯一的想法是改变框架本身的重力,但我尝试的一切都不起作用。谢谢!
//
// GameScene.swift
// Pong
//
// Created by Mac2 on 1/16/17.
// Copyright © 2017 Mac2. All rights reserved.
//
import SpriteKit
import GameplayKit
class GameScene: SKScene
{
var trump = SKSpriteNode()
var player = SKSpriteNode()
var opponent = SKSpriteNode()
override func didMove(to view: SKView)
{
//essentially link them to the physical nodes we created in the gamescene
trump = self.childNode(withName: "trump") as! SKSpriteNode
player = self.childNode(withName: "player") as! SKSpriteNode
opponent = self.childNode(withName: "opponent") as! SKSpriteNode
//to initialize the game we need the ball to be going somewhere so we make it go on an angle to the player (not opponent)
trump.physicsBody?.applyImpulse(CGVector(dx: -20, dy: -20))
let border = SKPhysicsBody(edgeLoopFrom: self.frame)
//create variable representing the frame or border of the gamescene
border.friction = 0 //we don't want friction to the borders
border.restitution = 1.0 //we want bouncyness to the borders
self.physicsBody = border //wrap it all up and save it as the physics representation of the gamescene frame
}
override func update(_ currentTime: TimeInterval)
{
// Called before each frame is rendered
}
}