Add sprites over a circular CGPath Swift - swift

How can I spawn a sprite repeatedly over the coordinates of a circular path?
So I have a circular path and I want the sprite to appear every 30ยบ for example (so in that case I would end up having the same sprite 12 times). The problem is that it doesn't matter what I do I cant get it to do so. Recently I found an article were it was shown how to do a clock, I used that sample code but I'm still stuck, I don't know what to replace drawRect for or if I have any other errors.
I would appreciate any help.
import SpriteKit
import UIKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
func degree2radian(a:CGFloat)->CGFloat {
let b = CGFloat(M_PI) * a/180
return b
}
func circleCircumferencePoints(sides:Int,x:CGFloat,y:CGFloat,radius:CGFloat,adjustment:CGFloat=0)->[CGPoint] {
let angle = degree2radian(360/CGFloat(sides))
let cx = x
let cy = y
let r = radius
var i = sides
var points = [CGPoint]()
while points.count <= sides {
let xpo = cx - r * cos(angle * CGFloat(i)+degree2radian(adjustment))
let ypo = cy - r * sin(angle * CGFloat(i)+degree2radian(adjustment))
points.append(CGPoint(x: xpo, y: ypo))
i--;
}
return points
}
func pointsLocation(#x:CGFloat, #y:CGFloat, #radius:CGFloat, #sides:Int) {
let points = circleCircumferencePoints(sides,x,y,radius)
let path = CGPathCreateMutable()
for p in enumerate(points) {
CGPathMoveToPoint(path, nil, p.element.x, p.element.y)
let blueDot = SKSpriteNode(imageNamed: "arrow.png")
blueDot.position.x = p.element.x
blueDot.position.y = p.element.y
addChild(blueDot)
CGPathCloseSubpath(path)
class View: UIView {
override func drawRect(rect: CGRect)
let rad = CGRectGetWidth(rect)/3.5
pointsLocation(x: CGRectGetMidX(rect), y: CGRectGetMidY(rect), radius: rad, sides: 8)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}

You code has a lot of syntax errors. That's why it doesn't work. After correcting the errors, the logic you used works.
class GameScene: SKScene,SKPhysicsContactDelegate {
override func didMoveToView(view: SKView) {
pointsLocation(x: 100, y: 100, radius: 50, sides: 12)
}
func degree2radian(a:CGFloat)->CGFloat {
let b = CGFloat(M_PI) * a/180
return b
}
func circleCircumferencePoints(sides:Int,x:CGFloat,y:CGFloat,radius:CGFloat,adjustment:CGFloat=0)->[CGPoint] {
let angle = degree2radian(360/CGFloat(sides))
let cx = x
let cy = y
let r = radius
var i = sides
var points = [CGPoint]()
while points.count <= sides {
let xpo = cx - r * cos(angle * CGFloat(i)+degree2radian(adjustment))
let ypo = cy - r * sin(angle * CGFloat(i)+degree2radian(adjustment))
points.append(CGPoint(x: xpo, y: ypo))
i--;
}
return points
}
func pointsLocation(#x:CGFloat, y:CGFloat, radius:CGFloat, sides:Int) {
let points = circleCircumferencePoints(sides,x: x,y: y,radius: radius)
let path = CGPathCreateMutable()
for p in enumerate(points) {
let blueDot = SKSpriteNode(imageNamed: "arrow.png")
blueDot.position.x = p.element.x
blueDot.position.y = p.element.y
addChild(blueDot)
}
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}

Related

Swift: Value Of A Variable Public But Still Local?

I change the value in a function and want to access the value in another function within the same class. My code:
class person{
var fieldsWidth = CGFloat()
var xPos = CGFloat()
var yPos = CGFloat()
var player = SKSpriteNode()
func addPlayer(gameScene: GameScene, x: CGFloat, y: CGFloat){
fieldsWidth = gameScene.screenWidth / CGFloat(hintergrund().fieldsX)
player = SKSpriteNode(imageNamed: "player")
player.size = CGSize(width: fieldsWidth, height: fieldsWidth)
player.position = CGPoint(x: x, y: y)
gameScene.addChild(player)
xPos = x
}
func move(gameScene: GameScene, point: CGPoint, fWidth: CGFloat){
print(xPos)
}
}
and the GameScene:
class GameScene: SKScene {
var screenWidth = CGFloat()
var screenHeight = CGFloat()
var touchLocation = CGFloat()
var fieldsWidth = CGFloat()
let player = person()
override func didMoveToView(view: SKView) {
screenWidth = self.size.width
screenHeight = self.size.height
fieldsWidth = screenWidth / CGFloat(hintergrund().fieldsX)
person().addPlayer(self, x: fieldsWidth/2, y: fieldsWidth/2)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
let touch = touches.first
var point = CGPoint()
point = touch!.locationInNode(self)
player.move(self, point: point, fWidth: fieldsWidth)
}
}
Somehow the value of xPos is just local in addPlayer. How can I access the value from xPos correctly? Hopefully you can help me.
The following code runs exactly as expected for me in a XCode Version 7.1 (7B91b) playground
class person{
var yPos = CGFloat()
func function1(y: CGFloat){
yPos = y
print(yPos) //Value of yPos is 31.25; correct!
}
func function2(){
print(yPos) //Value of yPos is 0.0; wrong!??
}
}
let foo = person()
foo.function1(31.25)
foo.function2() //Outputs 31.25
I think CGFloat is 0.0 by default so the most likely cause of your error is that you call function 2 before function one in your code. The error is somewhere else.
EDIT since you posted code. I would try this (create a new player and retain it -- I am not a sprite kit expert):
class GameScene: SKScene {
var screenWidth = CGFloat()
var screenHeight = CGFloat()
var touchLocation = CGFloat()
var fieldsWidth = CGFloat()
var player = person() // SEE HERE - Variable, so that you can reassign it
override func didMoveToView(view: SKView) {
screenWidth = self.size.width
screenHeight = self.size.height
fieldsWidth = screenWidth / CGFloat(hintergrund().fieldsX)
player = person().addPlayer(self, x: fieldsWidth/2, y: fieldsWidth/2) // SEE HERE - Create new player and retain it into your scene
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
let touch = touches.first
var point = CGPoint()
point = touch!.locationInNode(self)
player.move(self, point: point, fWidth: fieldsWidth)
}
}
PS: The above might work but really, from what I understand you need to create a player each time didMoveToView is called. If that is the case, then instead of doing this contrived addPlayer funciton, I would make a designated initialiser for the player class. Something like (untested):
func init(scene: SKScene, x: CGFLoat, y: CGFloat) {
// ETC...
}

How to create a slingshot mechanism in Swift, SpriteKit

I am trying to create a Sling shot mechanism where I rotate a node with an object attached at the end. The slingshot starts off with a touch and hold interaction to rotate the object and on release, launches the object attached at the end - A similar effect is seen here
This is my code for the rotation which has worked. Not sure how to start the joining and slinging part.
var touchingScreen = false
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
touchingScreen = true
println("Screen Touched")
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
touchingScreen = false
println("Screen Not Touched")
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
touchingScreen = false
println("Screen Not Touched")
}
override func update(currentTime: CFTimeInterval) {
if touchingScreen {
var RotatingAngle = CGFloat(M_PI)
var rotationDuration = 20.0
var rotateCanon = SKAction.rotateByAngle(CGFloat(RotatingAngle), duration: rotationDuration)
canon.runAction(rotateCanon)
} else if !touchingScreen {
var RotatingAngleTwo = CGFloat(0)
var rotationDurationTwo = 0.0
var rotateCanon = SKAction.rotateByAngle(CGFloat(RotatingAngleTwo), duration: rotationDurationTwo)
canon.runAction(rotateCanon)
}
}
Thanks for the help.
Some thoughts...
It's fairly straightforward to implement a slingshot as shown in the video if you break it down into smaller steps
If you represent the ball's position on the circle with polar coordinates, you can rotate the ball by simply incrementing the angle over time and then converting from polar to cartesian coordinates
When launched, the ball's trajectory should be tangent to the ball's position on the circle and its speed should be the same as its angular velocity.
and some code...
enum State {
case Stopped
case Rotating
case Launched
}
let two_pi = CGFloat(M_PI*2.0)
let pi = CGFloat(M_PI)
// These are useful vector/point operators
func * (left:CGPoint, right:CGFloat) -> CGPoint {
return CGPointMake(left.x*right, left.y*right)
}
func += (inout left:CGPoint, right:CGPoint) {
left = CGPointMake(left.x+right.x, left.y+right.y)
}
func * (left:CGVector, right:CGFloat) -> CGVector {
return CGVectorMake(left.dx*right, left.dy*right)
}
func / (left:CGVector, right:CGFloat) -> CGVector {
return CGVectorMake(left.dx/right, left.dy/right)
}
class GameScene: SKScene {
let shape = SKShapeNode(circleOfRadius: 7)
let radius:CGFloat = 30
var center = CGPointZero
var currentAngle = -pi/2
let angleIncr = two_pi / 60.0
var state:State = .Stopped
override func didMoveToView(view: SKView) {
scaleMode = .ResizeFill
// Set the center of the sling
center = CGPointMake (CGRectGetMidX(view.frame),CGRectGetMidY(view.frame))
addBall()
let circle = SKShapeNode(circleOfRadius: radius)
circle.position = CGPointMake (CGRectGetMidX(view.frame),CGRectGetMidY(view.frame))
addChild(circle)
}
// Adds a circle shape node at the bottom of the sling
func addBall() {
currentAngle = -pi/2
shape.fillColor = SKColor.blueColor()
shape.position = CGPointMake (center.x, center.y-radius)
shape.physicsBody = SKPhysicsBody(circleOfRadius: 7)
shape.physicsBody?.affectedByGravity = false
shape.physicsBody?.mass = 0.5
shape.zPosition = 1
addChild(shape)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch {
let location = touch.locationInNode(self)
if (state == .Stopped) {
// Start rotating the ball around the sling
state = .Rotating
}
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if (state == .Rotating) {
// Launch the ball on a vector tangent to its current position on the circle
state = .Launched
// Normal vector
var normal = CGVectorMake(shape.position.x-center.x, shape.position.y-center.y)
normal = normal / magnitude(normal)
// Tangent vector
let vector = CGVectorMake(normal.dy, -normal.dx)
// Convert angular to linear speed
let speed = angleIncr * 60.0 * radius
shape.physicsBody?.velocity = vector*speed
runAction(SKAction.waitForDuration(1.0)) {
self.shape.removeFromParent()
self.state = .Stopped
self.addBall()
}
}
}
override func update(currentTime: CFTimeInterval) {
switch (state) {
case .Rotating:
var point = angleToPoint(currentAngle) * radius
point += center
shape.position = point
currentAngle -= angleIncr
// Wrap at 2 pi
currentAngle %= two_pi
default:
break
}
}
func angleToPoint(angle:CGFloat) -> CGPoint {
return CGPointMake(cos(angle), sin(angle))
}
func magnitude(v1:CGVector) -> CGFloat {
return sqrt(v1.dx*v1.dx+v1.dy*v1.dy)
}
}
and a video...

How should I update the curve correctly with touchesMoved function?

I want to make a curve like, when user moved their finger, the curve changed its radian, but the code I did was seems something wrong, with many curve when I moved my finger:(
Here was my code below, and followed the terrible build's screenshot. Actually I also want to how to implement this function with UIPanGestureRecognizer.
import SpriteKit
import AVFoundation
import UIKit
class Home: SKScene {
var happiness:CGFloat {
return currentPoint.y
}
var currentPoint = CGPoint(x: 0, y: 1024)
override func didMoveToView(view: SKView) {
backgroundColor = UIColor.blueColor()
}
func drawhappiness() {
let pathNew2 = CGPathCreateMutable()
let startx:CGFloat = 268
let starty:CGFloat = 1024
let cp1x:CGFloat = 568
let cp1y:CGFloat = happiness
let cp2x:CGFloat = 968
let cp2y:CGFloat = happiness
let endx:CGFloat = 1292
let endy:CGFloat = 1024
CGPathMoveToPoint(pathNew2, nil, startx, starty)
CGPathAddCurveToPoint(pathNew2, nil, cp1x, cp1y, cp2x, cp2y, endx, endy)
let shapeNew2 = SKShapeNode()
shapeNew2.path = pathNew2
shapeNew2.strokeColor = UIColor.greenColor()
shapeNew2.lineWidth = 10
addChild(shapeNew2)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch:AnyObject in touches {
currentPoint = touch.locationInNode(self)
}
}
override func update(currentTime: NSTimeInterval) {
drawhappiness()
}
}
You are adding a new shape node to the scene each time you move your finger. To fix this, create a single shape with global scope in Home, configure the shape in didMoveToView (i.e., set line width, color), and update the shape's path property in drawhappiness.
For example,
class Home: SKScene {
let shapeNew2 = SKShapeNode()
var currentPoint = CGPoint(x: 0, y: 1024)
var happiness:CGFloat {
return currentPoint.y
}
override func didMoveToView(view: SKView) {
backgroundColor = UIColor.blueColor()
shapeNew2.strokeColor = UIColor.greenColor()
shapeNew2.lineWidth = 10
addChild(shapeNew2)
}
func drawhappiness() {
let pathNew2 = CGPathCreateMutable()
let startx:CGFloat = 268
let starty:CGFloat = 1024
let cp1x:CGFloat = 568
let cp1y:CGFloat = happiness
let cp2x:CGFloat = 968
let cp2y:CGFloat = happiness
let endx:CGFloat = 1292
let endy:CGFloat = 1024
CGPathMoveToPoint(pathNew2, nil, startx, starty)
CGPathAddCurveToPoint(pathNew2, nil, cp1x, cp1y, cp2x, cp2y, endx, endy)
shapeNew2.path = pathNew2
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch:AnyObject in touches {
currentPoint = touch.locationInNode(self)
}
}
override func update(currentTime: NSTimeInterval) {
drawhappiness()
}
}

moving pacman in swift

i am brand new to swift and i am trying to program a pacman. i am trying to move the pacman to the direction of the swipe, so far i have managed to move it to the edges of the screen, the problem is that when i try to move it not from the edge of the screen but in the middle of the swipe action, it just goes to the edge of the screen and moves to the swipe direction, here is the code for one direction:
var x = view.center.x
for var i = x; i > 17; i--
{
var origin: CGPoint = self.view.center
var move = CABasicAnimation(keyPath:"position.x")
move.speed = 0.13
move.fromValue = NSValue(nonretainedObject: view.center.x)
move.toValue = NSValue(nonretainedObject: i)
view.layer.addAnimation(move, forKey: "position")
view.center.x = i
}
the thing is that i know the problem which is when i swipe to the direction that i want the for loop will not wait for the animation to stop but it will finish the loop in less than a second and i need sort of delay here or other code.
This was an interesting question, so I decided to make an example in SpriteKit. There isn't any collision detection, path finding or indeed even paths. It is merely an example of how to make 'Pac-Man' change direction when a swipe occurs.
I have included the GameScene below:
class GameScene: SKScene {
enum Direction {
case Left
case Right
case Up
case Down
}
lazy var openDirectionPaths = [Direction: UIBezierPath]()
lazy var closedDirectionPaths = [Direction: UIBezierPath]()
lazy var wasClosedPath = false
lazy var needsToUpdateDirection = false
lazy var direction = Direction.Right
lazy var lastChange: NSTimeInterval = NSDate().timeIntervalSince1970
var touchBeganPoint: CGPoint?
let pacmanSprite = SKShapeNode(circleOfRadius: 15)
override func didMoveToView(view: SKView) {
let radius: CGFloat = 15, diameter: CGFloat = 30, center = CGPoint(x:radius, y:radius)
func createPaths(startDegrees: CGFloat, endDegrees: CGFloat, inout dictionary dic: [Direction: UIBezierPath]) {
var path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startDegrees.toRadians(), endAngle: endDegrees.toRadians(), clockwise: true)
path.addLineToPoint(center)
path.closePath()
dic[.Right] = path
for d: Direction in [.Up, .Left, .Down] {
path = path.pathByRotating(90)
dic[d] = path
}
}
createPaths(35, 315, dictionary: &openDirectionPaths)
createPaths(1, 359, dictionary: &closedDirectionPaths)
pacmanSprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
pacmanSprite.fillColor = UIColor.yellowColor()
pacmanSprite.lineWidth = 2
if let path = openDirectionPaths[.Right] {
pacmanSprite.path = path.CGPath
}
pacmanSprite.strokeColor = UIColor.blackColor()
self.addChild(pacmanSprite)
updateDirection()
// Blocks to stop 'Pacman' changing direction outside of a defined path?
//375/25 = 15 width
//666/37 = 18 height
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
touchBeganPoint = positionOfTouch(inTouches: touches)
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touchStartPoint = touchBeganPoint,
touchEndPoint = positionOfTouch(inTouches: touches) {
if touchStartPoint == touchEndPoint {
return
}
let degrees = atan2(touchStartPoint.x - touchEndPoint.x,
touchStartPoint.y - touchEndPoint.y).toDegrees()
var oldDirection = direction
switch Int(degrees) {
case -135...(-45): direction = .Right
case -45...45: direction = .Down
case 45...135: direction = .Left
default: direction = .Up
}
if (oldDirection != direction) {
needsToUpdateDirection = true
}
}
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
touchBeganPoint = nil
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
if let nodes = self.children as? [SKShapeNode] {
for node in nodes {
let p = node.position
let s = node.frame.size
//let s = node.size
if p.x - s.width > self.size.width {
node.position.x = -s.width
}
if p.y - s.height > self.size.height {
node.position.y = -s.height
}
if p.x < -s.width {
node.position.x = self.size.width + (s.width / 2)
}
if p.y < -s.height {
node.position.y = self.size.height + (s.height / 2)
}
if needsToUpdateDirection || NSDate().timeIntervalSince1970 - lastChange > 0.25 {
if let path = wasClosedPath ? openDirectionPaths[direction]?.CGPath : closedDirectionPaths[direction]?.CGPath {
node.path = path
}
wasClosedPath = !wasClosedPath
lastChange = NSDate().timeIntervalSince1970
}
updateDirection()
}
}
}
// MARK:- Helpers
func positionOfTouch(inTouches touches: Set<NSObject>) -> CGPoint? {
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
return location
}
return nil
}
func updateDirection() {
if !needsToUpdateDirection {
return
}
pacmanSprite.removeActionForKey("Move")
func actionForDirection() -> SKAction {
let Delta: CGFloat = 25
switch (direction) {
case .Up:
return SKAction.moveByX(0.0, y: Delta, duration: 0.1)
case .Down:
return SKAction.moveByX(0.0, y: -Delta, duration: 0.1)
case .Right:
return SKAction.moveByX(Delta, y: 0.0, duration: 0.1)
default:
return SKAction.moveByX(-Delta, y: 0.0, duration: 0.1)
}
}
let action = SKAction.repeatActionForever(actionForDirection())
pacmanSprite.runAction(action, withKey: "Move")
needsToUpdateDirection = false
}
}
The repository can be found here
I have added the MIT license, so you can fork this repository if you wish. I hope this helps.

Swift Center on Camera not working when ApplyingImpulse in another class

I'm new to swift programming and have been stuck on this issue for the last week. I am trying to centre on a hero while applying impulse to him. My code works if I create a hero in the scene class and centre him but it doesn't work when I put a hero in another class and try to centre him from scene class. Now centre on works if I just move him by changing his x or y position but not if I apply impulse. It seems that when a hero is in a separate class, when impulse is applied x and y while he is in motion is showing up as a nil, however when he is in the same class than x and y while in the motion are showing up ok. Any help is much appreciated.
Code where Center ON works with ApplyImpulse when everything is in the same class*****
class GameScene: SKScene {
var hero:SKSpriteNode?
var mazeWorld:SKNode?
var player=Player()
var heroLocation:CGPoint = CGPointZero
override func didMoveToView(view: SKView) {
mazeWorld = childNodeWithName("mazeWorld")
heroLocation = mazeWorld!.childNodeWithName("sPoint")!.position
self.anchorPoint = CGPoint(x: 0.5,y: 0.3)
hero?.position = heroLocation
hero = SKSpriteNode(imageNamed:"hero_walk_down_0")
hero!.physicsBody?.dynamic = false
hero!.physicsBody?.affectedByGravity = true
hero!.physicsBody?.pinned = false
hero!.physicsBody = SKPhysicsBody(rectangleOfSize: hero!.size)
hero!.physicsBody?.mass = 1.0;
hero!.setScale(0.8)
mazeWorld!.addChild(hero!)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
/* Called when a touch begins */
for touch: AnyObject in touches {
hero!.physicsBody?.applyImpulse(CGVector(dx: 240, dy: 550))
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
func centerOnNode(node:SKNode){
let cameraPositionInScene:CGPoint = self.convertPoint(node.position, fromNode: mazeWorld!)
mazeWorld!.position = CGPoint(x:mazeWorld!.position.x - cameraPositionInScene.x, y: mazeWorld!.position.y - cameraPositionInScene.y)
}
override func didSimulatePhysics() {
self.centerOnNode(hero!)
}
}
**** Here is the code with Center ON that doesn't work with apply impulse for some reason
import SpriteKit
class GameScene: SKScene {
var hero:SKSpriteNode?
var mazeWorld:SKNode?
var player=Player()
var heroLocation:CGPoint = CGPointZero
override func didMoveToView(view: SKView) {
mazeWorld = childNodeWithName("mazeWorld")
heroLocation = mazeWorld!.childNodeWithName("sPoint")!.position
self.anchorPoint = CGPoint(x: 0.5,y: 0.3)
player.position = heroLocation
mazeWorld!.addChild(player)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
/* Called when a touch begins */
for touch: AnyObject in touches {
player.jumpRight()
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
func centerOnNode(node:SKNode){
let cameraPositionInScene:CGPoint = self.convertPoint(node.position, fromNode: mazeWorld!)
mazeWorld!.position = CGPoint(x:mazeWorld!.position.x - cameraPositionInScene.x, y: mazeWorld!.position.y - cameraPositionInScene.y)
}
override func didSimulatePhysics() {
self.centerOnNode(player)
}
}
import Foundation
import SpriteKit
class Player: SKNode{
var objectSprite:SKSpriteNode?
override init()
{
super.init()
objectSprite = SKSpriteNode(imageNamed:"hero_walk_down_0")
objectSprite!.physicsBody?.dynamic = false
objectSprite!.physicsBody?.affectedByGravity = true
objectSprite!.physicsBody?.pinned = false
objectSprite!.physicsBody = SKPhysicsBody(rectangleOfSize: objectSprite!.size)
objectSprite!.physicsBody?.mass = 1.0
objectSprite!.setScale(0.8)
addChild(objectSprite!)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func jumpRight()
{
objectSprite!.physicsBody?.applyImpulse(CGVector(dx: 240, dy: 550))
}
}