The O.G. Virtual learning! Buy one, get 2 more Lifetime Memberships! - Click Here!

gage kolman

Forum Replies Created

Viewing 8 posts - 1 through 8 (of 8 total)
  • Posted in:
  • April 6, 2016 at 12:13 pm #145623

    I’m trying to combine your joystick tutorial with your missile tutorial. I understand and have spawned bullets based on the Z rotation and angles but how do you spawn a bullet based on a joysticks rotation? since the joystick rotation is declared in a touches moved function how do you spawn and move a bullet based on that location since when you’re creating your spawn bullet function you can’t spawn it based on the zRotation and/or angle because you haven’t defined those yet? i noticed in your rotation video you used a UIRotationGestureRecognizer which can be defined for the entire class since it is already programmed as a UITouch/tapped whatever, as apposed to a joystick defined in a touches moved. should i make my joystick it’s own method then call upon it in touches moved? if so how do i do that? Ive spent quite a while trying to find solutions to this only to find a solution that creates a different problem. Semicolon frown face. Btw love the vids.you articulate quite well when explaining things, you break down pretty intimidating concepts into quick and easy to follow videos

  • July 19, 2016 at 2:16 pm #153147

    yes i do have a rock solid reason lol, it is a shooting game with a joystick so his torso needs to be able to move around and aim and his legs, need to be a able to walk forwards, backwards and jumping. while aiming. The torso rotates 360 degrees. I would have to combine 30 aiming frames, with 50 walking frames with 12 different guns and 6 different characters. So i would have to match up and create 30 x 50 x 12 x 6 frames.

  • May 16, 2016 at 5:52 pm #149896

    It worked! I used your timer method which was called by a bool value in the update method, and because i defined angle for the whole class i was able to use the same angle for the spawn location in a separate bullet method. thank you so much!

  • May 16, 2016 at 2:38 pm #149892

    thank you so much! You don’t know how much time you saved me i was scratching my head for a few days lol, Ill recommend your website as well 🙂

  • May 14, 2016 at 3:09 pm #149848

    Ok, how do you define the angle for the whole class? for

    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)

    More specifically how do you define the CGvector? because you can’t use location or joystick base to define the x and y values of the vector

  • May 13, 2016 at 8:52 pm #149808

    ok, hopefully, last question lol. How to I update the spawn location of the bullet? since you’re saying i need to add the child in the update function. However i need to add the bullet1 child in the same method where i define the angle of the joystick. Otherwise i get an error saying use of undeclared identifier “angle” because i defined angle in my touches moved and touches began. Your idea makes sense I’m just trying to make it work

  • May 13, 2016 at 2:17 pm #149787

    Yes, I have an update method but nothing inside for the bullet spawn method. If you use the update method for bullet spawn instead of the run block method i used every 0.25 seconds, would that limit me to only one fire rate? 1 bullet per second?

  • May 11, 2016 at 1:55 pm #149701

    Thank you for your help! It made sense, i created a bool called fireWeapon and a run block method in my touches began and touches moved, however how would i go about my update method? Since there is no method to call because my bullet spawn location was defined in my touches moved. Could you maybe edit my code just a little? I’ve been stuck on this for a while 🙁

    
    override func touchesBegan(touches: Set<UITouch>, withEvent event:UIEvent?) {
    
            for touch in touches {
    
                let location = touch.locationInNode(self)
                let node = nodeAtPoint(location)
    
                if (CGRectContainsPoint(joystick.frame, location)) {
    
                    stickActive = true
                    fireWeapon = true
                }else{
    
                    stickActive = false
                }
    
                if stickActive == true && fireWeapon == true{  if fireWeapon == false {}
                    
                let bulletAction = SKAction.runBlock({
                let v = CGVector(dx: location.x - self.joystickBase.position.x, dy:     
                location.y - self.joystickBase.position.y)
                let angle = atan2(v.dy, v.dx) //where angle is defined "in radians"
                let deg = angle * CGFloat(180 / M_PI)//converts radains to degrees and 
                generates a degree when touchesMoved == true
                 
                 print(deg + 180) // prints degree in debugging
                 self.hero.zRotation = angle - 1.57079633 //rotates with angle of joy 
                 stick
    
                    let bullet1:Bullet1 = Bullet1()
                    bullet1.createBullet1()
                
           bullet1.position = CGPoint (x: self.hero.position.x , y: self.hero.position.y)   
           // Bullet spawn @ anchor point
    
           let xDist:CGFloat = sin(angle - 1.5709633) * 35 //bullet spawn location
           let yDist:CGFloat = cos(angle - 1.5709633) * 35 //bullet spawn location
    
             bullet1.position = CGPointMake( self.hero.position.x - xDist, 
             self.hero.position.y + yDist) //spawning bullet @ defined location
                    
             let xDistMove:CGFloat = sin(angle - 1.5709633) * 700 //Bullet max x distance
             let yDistMove:CGFloat = cos(angle - 1.5709633) * 700 //Bullet max y distance
                    
             let bulletMovementY = SKAction.moveToY(self.hero.position.y + yDistMove, 
             duration: 1) //Bullet y speed
             let bulletMovementX = SKAction.moveToX(self.hero.position.x - xDistMove, 
             duration: 1) //Bullet x speed
    
             bullet1.runAction(bulletMovementY)
             bullet1.runAction(bulletMovementX)
                        
             self.addChild(bullet1)
                    })
    
             let wait = SKAction.waitForDuration(0.25)
             let completeSequence = SKAction.sequence([bulletAction, wait])
             let repeatShootingActionForever =
             SKAction.repeatActionForever(completeSequence)
             self.runAction(repeatShootingActionForever, withKey: "BulletAction")
                }
                
                if stickActive == false{
                    
                    fireWeapon = false
                }}}
    
     override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    
            for touch in touches {
    
                let location = touch.locationInNode(self)
    
                if stickActive == true && fireWeapon == true{  if fireWeapon == false {}
                   
                  let v = CGVector(dx: location.x - joystickBase.position.x, dy: 
                  location.y - joystickBase.position.y)
                  let angle = atan2(v.dy, v.dx) //where angle is defined "in radians"
                  let deg = angle * CGFloat(180 / M_PI)//converts radains to degrees and 
                  generates a degree when touchesMoved == true
                  let length: CGFloat = joystickBase.frame.size.height / 2 //sets maximum 
                  distance for joystick ball
                  print(deg + 180) // prints degree in debugging
    
                    joystick.position = location
               self.hero.zRotation = angle - 1.57079633 //rotates with angle of joy stick
               let xDist:CGFloat = sin(angle - 1.5709633) * 35 //bullet spawn location
               let yDist:CGFloat = cos(angle - 1.5709633) * 35 //bullet spawn location
                    
                    bullet1.position = CGPointMake( self.hero.position.x - xDist, 
                    self.hero.position.y + yDist) //spawning bullet @ defined location
                    
             let xDistMove:CGFloat = sin(angle - 1.5709633) * 700 //Bullet max x distance
             let yDistMove:CGFloat = cos(angle - 1.5709633) * 700 //Bullet max y distance
                    
              let bulletMovementY = SKAction.moveToY(self.hero.position.y + yDistMove, \    
              duration: 1) //Bullet y speed
              let bulletMovemenX = SKAction.moveToX(self.hero.position.x - xDistMove, 
              duration: 1) //Bullet x speed
    
              bullet1.runAction(bulletMovementY)
              bullet1.runAction(bulletMovemenX)
    
              if (CGRectContainsPoint(joystickBase.frame, location)) {
    
                }else{
    
                        let xDist:CGFloat = sin(angle - 1.5709633) * length 
                        let yDist:CGFloat = cos(angle - 1.5709633) * length 
    
              joystick.position = CGPointMake(joystickBase.position.x - xDist, 
              joystickBase.position.y + yDist)
    
                  }
                }
              }
            }
    

    this method works kinda-ish, the problem I’m having is that i can’t figure out a way to change the spawn location of the bullet when the joystick is moved, with this method the bullet spawns in the direction of the first click and does not update when the joystick is moved around. Which makes sense because you said i need to call something in my update method, how do i do that? Oh and the create bullet class is about the same as your create enemy missile class so i thought it was redundant to add. Thanks for your help! i appreciate it so much

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



Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.

Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!


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