All Access Lifetime Membership Only $99 - Expires: - Click Here!

Diego Aguilar

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Posted in:
  • October 14, 2016 at 2:07 am #156979

    Problem solved thank you for help.

  • October 13, 2016 at 10:15 am #156929

    tried it unfortunately it didn’t resolve my problem.

    https://drive.google.com/open?id=0B_YF_WUGmxwLdUFRc1BLTFhzaEU

    I’ve attached a link to my project if you would like to take a look at it.

  • October 11, 2016 at 3:42 pm #156879

    Below is the code that I wrote following your tutorial. As my gameHero moves through the scene the joystick stops working I can always see it but it doesn’t work.

    import Foundation
    import SpriteKit

    enum BodyType:UInt32 {

    case player = 1
    case ground = 2
    }

    class LevelOneScene: SKScene, SKPhysicsContactDelegate {

    // let for your buttons
    // let moveLeftBtn = SKSpriteNode(imageNamed: “LeftBtn”)
    // let moveRightBtn = SKSpriteNode(imageNamed: “RightBtn”)
    let jumpBtn = SKSpriteNode(imageNamed: “JumpBtn”)
    let attacKBtn = SKSpriteNode(imageNamed: “AttackBtn”)

    let base = SKSpriteNode(imageNamed:”Base”)
    let ball = SKSpriteNode(imageNamed:”Ball”)

    // let for the player
    let gameHero = Player(imageNamed: “Idle 0”)
    var playerSpeedX:CGFloat = 0
    var playerSpeedY:CGFloat = 0

    var jumpAmount:CGFloat = 0
    var maxJump:CGFloat = 22

    var attackAmount:CGFloat = 0
    var maxAttack:CGFloat = 8

    var walkAction:SKAction?
    var idleAction:SKAction?
    var attackAction:SKAction?
    var jumpAction:SKAction?

    var maxSpeed:CGFloat = 5

    var isAttacking:Bool = false
    var isJumping:Bool = false
    var doubleJumpAlreadyUsed:Bool = false
    var walkingSlow:Bool = false

    // Camera
    var gameCamera:SKCameraNode?

    var stickActive:Bool = false

    var strictCompassMovements:Bool = false

    // try to move character

    override func didMove(to view: SKView) {

    // Initial Setup
    physicsWorld.contactDelegate = self
    self.view?.isMultipleTouchEnabled = true
    self.backgroundColor = SKColor.black

    gameHero.position = CGPoint(x: 0, y: 0)
    gameHero.setScale(fabs(0.5))
    self.addChild(gameHero)

    //self.addChild(base)

    base.zPosition = 99
    base.position = CGPoint(x: -400, y: -200)

    //self.addChild(ball)
    ball.zPosition = 100
    ball.position = base.position

    gameCamera = self.childNode(withName: “MainCamera”) as? SKCameraNode!
    gameCamera?.addChild(base)
    gameCamera?.addChild(ball)

    createGrounds()

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    /* Called when a touch begins */

    for touch in (touches ) {

    let location = touch.location(in: self)

    if atPoint(location).name == “AttackBtn” {

    stickActive = false
    gameHero.attack()

    } else if atPoint(location).name == “JumpBtn” {

    stickActive = false
    gameHero.jump()

    } else if (location.x < 5000) {

    stickActive = true

    gameHero.startWalk()

    ball.alpha = 0.4
    base.alpha = 0.4

    } else {
    print( “touch down was on right side of screen, you maybe missed a button”)
    stickActive = false

    }
    }
    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

    for touch in (touches ) {
    let location = touch.location(in: self)

    if (stickActive == true) {

    let v = CGVector(dx: location.x – base.position.x, dy: location.y – base.position.y)
    let angle = atan2(v.dy, v.dx)

    // let deg = angle * CGFloat( 180 / M_PI)
    //println( deg + 180 )

    let length:CGFloat = base.frame.size.height / 2

    //let length:CGFloat = 40

    let xDist:CGFloat = sin(angle – 1.57079633) * length
    let yDist:CGFloat = cos(angle – 1.57079633) * length

    if (base.frame.contains(location)) {

    ball.position = location

    } else {

    ball.position = CGPoint(x: base.position.x – xDist, y: base.position.y + yDist)

    }

    // set up the speed

    let multiplier:CGFloat = 0.1

    gameHero.playerSpeedX = v.dx * multiplier

    gameHero.adjustXSpeedAndScale()

    } // ends stickActive test

    }
    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

    resetJoyStick()

    if (stickActive == true) {

    // let go for joystick

    gameHero.stopWalk()
    gameHero.playerSpeedX = 0

    } else if (stickActive == false) {

    //assumes let go of a button
    }
    }

    func resetJoyStick(){

    let move:SKAction = SKAction.move(to: base.position, duration: 0.2)
    move.timingMode = .easeOut

    ball.run(move)
    }

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

    gameCamera?.position = gameHero.position

    if ( self.isPaused == false) {

    gameHero.update()

    }

    }

    func createGrounds() {

    let ground = SKSpriteNode(imageNamed: “Ground”)
    ground.name = “Ground”
    ground.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    ground.position = CGPoint(x: -200, y: -300)
    ground.zPosition = 10
    ground.physicsBody = SKPhysicsBody(rectangleOf: ground.size)
    ground.physicsBody?.affectedByGravity = true
    ground.physicsBody?.isDynamic = false
    ground.physicsBody?.categoryBitMask = BodyType.ground.rawValue
    ground.physicsBody?.collisionBitMask = BodyType.player.rawValue
    ground.physicsBody?.contactTestBitMask = BodyType.player.rawValue
    self.addChild(ground)

    let ground2 = SKSpriteNode(imageNamed: “Ground”)
    ground2.name = “Ground”
    ground2.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    ground2.position = CGPoint(x: 1200, y: -250)
    ground2.zPosition = 10
    ground2.physicsBody = SKPhysicsBody(rectangleOf: ground.size)
    ground2.physicsBody?.affectedByGravity = true
    ground2.physicsBody?.isDynamic = false
    ground2.physicsBody?.categoryBitMask = BodyType.ground.rawValue
    ground2.physicsBody?.collisionBitMask = BodyType.player.rawValue
    ground2.physicsBody?.contactTestBitMask = BodyType.player.rawValue
    self.addChild(ground2)
    }
    }

Viewing 3 posts - 1 through 3 (of 3 total)



Make money just by sharing links to our site!... Thats how easy Affiliate programs are!

Earn when you refer any buyer! 30 day tracking. Commissions 33%-50% (and recurring on subscription products)!


Uh oh, missing your affiliate ID. Create one real quick