let randomNumber = arc4random_uniform(2)
let x: CGFloat = randomNumber == 0 ? 1 : -1
enemy.position = CGPoint(x: (CGFloat(arc4random_uniform(UInt32(UIScreen.main.bounds.width))) * x), y: UIScreen.main.bounds.height)
here is my code for enemy spawn, it works but some of my enemies are spawning outside of my screen. What can i change to make them all spawn inside the border
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
How can i change my objects gravity without having my player fall with it. I added
physicsWorld.gravity = CGVector(dx: 0, dy: 0)
on my players movement and affectedByGravity on both my object and player. If I change dy to -9.8, my object falls but along with my player
Im getting a overridden error for my player and enemy. I made a enemy file and added this code into my gamescene. My enemy only spawns in if i delete my player movement code
func spawnEnemy() {
let enemy = Enemy(image: SKSpriteNode(imageNamed: "enemy"))
self.addChild(enemy)
}
override func update(_ currentTime: TimeInterval) {
spawnEnemy()
}
Code seems fine however when i run the simulator in xcode or on my phone and tilt, the player doesnt move.
override func update(_ currentTime: TimeInterval) {
if let accelerometerData = motionManager?.accelerometerData {
physicsWorld.gravity = CGVector(dx: accelerometerData.acceleration.x * -50, dy: accelerometerData.acceleration.y * 50)
}
Do i need gamescene.sks because i deleted the grid and the file
I deleted the grid on gamescene.sks and i dont know how to get it back. Now my game wont run