Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cody Adkins
7,260 PointsMaking SKSpriteNode stay on screen boundaries...
Hello, I am creating a beginners Xcode game. Seems to be a popular rookie project on Youtube. I cannot get my SKSpriteNodes to stay within the boundaries of the screen. I thought by -30 from self.view.width it would keep it inside. But it is not. Attached is the code and youtube link.
https://www.youtube.com/watch?v=CeW6SCQv--o
func spawnEnemys() { let enemy = SKSpriteNode(imageNamed: "Twister")
let minimumValue = self.size.width/8
let maximumValue = SELF.SIZE.WIDTH - 30
let spawnPoint = UInt32(maximumValue - minimumValue)
enemy.position = CGPoint(x: CGFloat(arc4random_uniform(spawnPoint)), y: self.size.height)
let enemyAction = SKAction.moveToY(-300, duration: 3.0)
enemy.runAction(SKAction.repeatActionForever(enemyAction))
self.addChild(enemy)
}