Post

Replies

Boosts

Views

Activity

SpriteKit Gesture
I am wondering if anyone may be able to help advise how I can change the following code, essentially I am trying to incorporate X2 gamescene buttons that do the following func:1) Tap to fly (This I have working)2) Tap to shoot a projectile from Player position (I do not have working).My problem is I currently have the fly func set when touched anywhere on the screen.. I have tried the following :This is in reference to my GameScene : I thought in order to split this out I would need a node on the screen to reference this function. This does not error in the console but does not appear in the GameScene.In GameScene, I have declared a button within didmove func: // Button to trigger shooting node from player: let btnTest = SKSpriteNode(imageNamed: "Crater") btnTest.setScale(0.2) btnTest.name = "Button" btnTest.zPosition = 10 btnTest.position = CGPoint(x: 100, y: 200) self.addChild(btnTest) 2. In the Playerclass I have the following, var shooting = false var shootAnimation = SKAction() var noshootAnimation = SKAction() Init func: self.run(noshootAnimation, withKey: "noshootAnimation") let projectile = SKSpriteNode(imageNamed: "Crater") projectile.position = CGPoint (x: 100, y: 50) projectile.zPosition = 20 projectile.name = "projectile" // Assigning categories to Game objects: self.physicsBody?.categoryBitMask = PhysicsCategory.plane.rawValue self.physicsBody?.contactTestBitMask = PhysicsCategory.ground.rawValue self.physicsBody?.collisionBitMask = PhysicsCategory.ground.rawValue self.physicsBody?.applyImpulse(CGVector(dx: 300, dy: 0)) self.addChild(projectile) // Start the shoot animation, set shooting to true: func startShooting() { self.removeAction(forKey: "noshootAnimation") self.shooting = true } // Stop the shoot animation, set shooting to false: func stopShooting() { self.removeAction(forKey: "shootAnimation") self.shooting = false }// This node appears in the gamescene alongside the player : 🙂 Finally back to the GameScene I have :override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in (touches) { let location = touch.location(in: self) let nodeTouched = atPoint(location) if let gameSprite = nodeTouched as? GameSprite { gameSprite.onTap() } // Check the HUD buttons which I have appearing when game is over… if nodeTouched.name == "restartGame" { // Transition to a new version of the GameScene // To restart the Game self.view?.presentScene(GameScene(size: self.size), transition: .crossFade(withDuration: 0.6)) } else if nodeTouched.name == "returnToMenu"{ // Transition to the main menu scene self.view?.presentScene(MenuScene(size: self.size), transition: . crossFade(withDuration: 0.6)) } } Player.startFly() player.startShooting() } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { Player.stopFly() player.stopShooting() } override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { Player.stopFly() player.stopShooting() } override func update(_ currentTime: TimeInterval) { player.update() }}Unfortunately nothing happens in the GameScene and the node doesn’t fire when the screen is pressed, with the code above is there anyway I can amend this to allow for both ‘tap to fly’ + ‘tap to shoot’ functions. I still can’t figure out how to get the button I had declared early on in the GameScene to appear in which my gesture / touch position can be localised to this node on the screen as oppose to the whole screen in which I have currently..I can say this sounded more simple in my head to begin with than actually coding together… having a nightmare..Please can anyone help advise where I can correct this code?Thanks again!Tom---
0
0
439
May ’20
Camera Position ahead of player
Hey, I currently have my SKCamera node centered over my player perfectly in the screen, I am wondering if anyone can help in how I can place the camera node just ahead of player? This is the code I have currently : In GameScene : var screenCenterY:CGFloat = 0 In didMove function screenCenterY = self.size.height / 2 In didSimulatePhysics var cameraYPos = screenCenterY cam.yScale = 1 cam.xScale = 1 Self.camera!.position = CGPoint (x: player.position.x, y: cameraYPos I’m trying to position the player on the left of the screen whilst the camera stays in the middle?? New to Xcode - any help / suggestions are much appreciated. I assume my problem is that I am referencing the player position, whereas I should be taking the coordinators for the middle screen only? My player position has already been defined in the player class at (x: 50, y:250) Thanks, AJ
2
0
603
May ’20
Scene Kit Objects -Z.Position Faulting
Hello, I have had some issues within SceneKit in where I add my assets to the SceneKit editor, once the image is in place I always set the z.position to (-1) / behind the player... Sometimes on running the simulation I notice that occasionally the player either goes under or over the image assets I’ve added.. I’ve changed to either -10 / -50 etc assuming this will place the images back further in the scene. Still getting the same result at random. Maybe a silly question but I thought I’d ask as I must be doing something wrong, has anyone come across this before? :/ Thanks in advance, AJ
0
0
353
May ’20
Game scene Duplication
Hello, I am fairly new to Xcode and after a few months have a successful endless runner game! I have been curious to see if it is possible to create a second level, basing from duplicating my original game scene. I have tried this out of curiosity and I am able to access on simulation the X2 game scenes- My problem is that everything in the game scene including my player is completely still. When I tap the screen my player animations work, however I have no movement of backgrounds / no player movement either. It was a little odd as this worked before I attempted to duplicate. Can anyone help suggest what could be causing this / or the correct method to approach when attempting to utilise your current code to create a second game scene... Any help would be much appreciated! It’s taken a lot of head scratching over the past few weeks.. :( Thanks in advance, AJ
0
0
328
May ’20