Hello, Just starting to learn Xcode and I can test the first chapter's app on my iPhone if it's conncted via USB-C. The book walks me through the part where I can allow Xcode to connect to the iPhone via WiFi, just checking "Connect via Network."Yet Xcode cannot find my phone unless it's connected via USB. When I go to Devices that checkbox stays checked, unless I unplug the phone it which case that box doesn't even appear.And yes, they are both on the same WiFi, it's the only one I have and it's up and running.Any thoughs?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
New to Macs and still learning Swift. My first goal is a game so I actually am looking for TWO recommendations:Is there an advantage to Swift vs. Objective C when programming game apps?Can anyone recommend a decent book for beginners? I'm not a beginner, however my last heavy experience was with Perl, C, and the WindowsSDK. So am behind the times.Thank you
Still new, but slowly building my first game, and getting there.
I'd like to be able to add a fading streak or trail as one my SKSpriteNodes returns to it's home base.
The only thing I can think of is calculating the distance, breaking it down into x moments, then gradually move the Sprite a little, with some fade options, and then repeat in a loop till it gets back to home base.
I know that has to be wrong because it's just so ugly.
When I look at the Sprite Kit's Particle File, it has so few options. And I'm not really sure that's what I should be looking at. I have also looked at SKAction's options, and if there's an option there I'm missing it. A good book or website dedicated to SKAction would be nice.
But right am just looking for my solution.
Thanks as always
Here's the code I have:
myGSlot.physicsBody = SKPhysicsBody(rectangleOf: size)
myGSlot.physicsBody!.affectedByGravity = true
myGSlot.physicsBody!.affectedByGravity = true
myGSlot.physicsBody!.isDynamic = true
myGSlot.physicsBody!.restitution = 0.2
Is there a way I don't have to constantly unwrap myGSlot.physicsBody?
I would like to create a rectangular box where only the outline has an SKPhysicsBody. Because I would like to have multiple physics bodies in the rectangle.
Right now as a solid it's causing a lot of complications.
Below is the code from GameViewController I use to present my GameScene. GameScene comes out respecting the safe areas (iPhone X).
However if I create an SKSprite node, the coords for the upper screen draw into the safe area.
My impression was that would not happen, nor can I find the top and bottom anchors.
p.s. on a side note, I cannot view originalS.frame.width or originalS.frame.height in the debugger, they come out as invalid expressions. yet they don't crash the app.class GameViewController: UIViewController {
		private let myView : UIView = {
				let myView = UIView()
myView.translatesAutoresizingMaskIntoConstraints = false
myView.backgroundColor = .clear
return myView
}()
private func addConstraints(){
var constraints = [NSLayoutConstraint]()
constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
NSLayoutConstraint.activate(constraints)
}
let logo = UIImage(named: "startup")
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myView)
addConstraints()
if let view = self.view as! SKView?
{
myGlobalVars.widthPixels = UIScreen.main.nativeBounds.width
myGlobalVars.heightPixels = UIScreen.main.nativeBounds.height
myGlobalVars.widthPoints = UIScreen.main.bounds.width
myGlobalVars.heightPoints = UIScreen.main.bounds.height
originalS = myView
originalS.backgroundColor = .clear
originalS.translatesAutoresizingMaskIntoConstraints = false
originalS.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor).isActive = true
originalS.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
originalS.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor).isActive = true
originalS.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor , constant: -0).isActive = true
var scene : GameScene!
DispatchQueue.main.async {
scene = GameScene(size: CGSize(width: originalS.frame.width,
height: originalS.frame.height))
scene.anchorPoint = CGPoint(x: 0.0, y: 0.0)
scene.backgroundColor = .black
scene.scaleMode = .aspectFit
myGlobalVars.sceneRect = scene.frame
myGlobalVars.gameScene = scene
view.isHidden = false
view.presentScene(scene)
}
myGlobalVars.passGo = true
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
view.showsPhysics = false
}
}
I have two objects that collide even when they are not moving, and are apart from each other.
Now I know it's rude not to include code. But before I start reducing my code to post it up here, at let me describe what's happening with a photo. Maybe I'll get lucky and it's something I'm overlooking since I am still learning.
Here are the two screenshots. I had to spilt the link because the forum won't let me post it completely.
https ://i.ibb.co/QYHcp3L/Untitled.png
In the left shot, everything you see, the two balls, and the left and bottom edges are created where you see them. The only thing I have not done is given the edges their SKPhysicsBodies. The edges purposes are just to keep the balls on screen. My intent is to keep the edges just a little off screen, but the same thing happens. I merely moved them in for the screenshots.
But in the right shot, I've just given the edges their physics bodies, isPinned is set to true for the edges and the masks are set so that ball and edge collide.
Yet for some reason, with nothing moving, the red ball collides with the bottom and left edges till it's pushed just off to the side.
This is all done under didMove. And I even tried not giving the edges their physics attributes till I tapped on the blank screen, and boom....everything suddenly collided.
If I have missed some sort of setting, would love to know. In the meantime, I'll start condensing all my code into one much smaller file.
May sound silly, but just wanted to make sure that if I import /declare a module in Swift, say:
#import GameplayKit
And use none of its definitions, will the Xcode compiler not include it in the build?
Update Xcode via the app store is like losing a day. I was hoping I could find the update (dmg) somewhere on Apple to download ver 12.2. Yet the only download I found was for 12.3 beta.
So was hoping the updates are located somewhere.
Thank you
I just finished a very rough draft of my first app whilst learning Swift. So I decided to remake the app so that my code would be cleaner/more compliant, etc.
I don't use storyboards, I launch from GameViewControler, both apps are set for a minimum iOS of 13.5, and both are run on the iPhoneX simulator...as well as my iPhoneX itself.
But for some reason in each different app, I am getting different screen sizes! Am going to assume I did something different when I "created" the new project, but am unable to distinguish what that is.
Here is my entire GameViewController.swift file and have included a photo of the different screen sizes. I break right after I get both the bounds and native bounds.
The two different sizes are:
In the 1st project I get
wPixels 1125
hPixels 2436
wPoints 375
hPoints 812
and the 2nd
wPixels 960
hPixels 1440
wPoints 320
hPoints 480
import UIKit
import SpriteKit
class GameViewController: UIViewController {
		override func viewDidLoad() {
				super.viewDidLoad()
				if let view = self.view as! SKView? {
						var wPix = UIScreen.main.nativeBounds.width
						var hPix = UIScreen.main.nativeBounds.height
						var wPoi	= UIScreen.main.bounds.width
						var hPoi	= UIScreen.main.bounds.height
						var scene : GameScene!
						DispatchQueue.main.async { [self] in
										 scene = GameScene(size: CGSize(width: wPoi, height: hPoi))
						scene.anchorPoint = CGPoint(x: 0.0, y: 0.0)
						scene.backgroundColor = .red
						scene.scaleMode = .aspectFit
						view.isHidden = false
						view.presentScene(scene)
						}
						view.ignoresSiblingOrder = true
						view.showsFPS = true
						view.showsNodeCount = true
						view.showsPhysics = true
				}
		}
		override var shouldAutorotate: Bool {
				return false
		}
		override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
				if UIDevice.current.userInterfaceIdiom == .phone {
						return .allButUpsideDown
				} else {
						return .all
				}
		}
		override var prefersStatusBarHidden: Bool {
				return false
		}
}
From within my GameViewController's viewDidLoad() function I do two things:
1- I create a sub UIVIew, myView, which is added to the main view,
2- I call my function, addConstraints, which is in the GameViewController's code.
When I create GameScene, self.myView.frame.width & self.myView.frame.height contain the correct values, and abide by the safeAreaLayout guides.
I want to make my code clearer, so I've moved the addConstraints function to a separate file. But when I run my app that way self.myView.frame.width & self.myView.frame.height are zero.
So am curious if I am somehow translating the function incorrectly, or maybe this is something I can't move outside of the main code?
The first block is the original code, the 2nd is the function//located with GameViewControl		
private func addConstraints(){
				var constraints = [NSLayoutConstraint]()
				
constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
NSLayoutConstraint.activate(constraints)
}
translated into a function//called from GameViewControl
		createConstraints(view: myView)
....
//located outside of GameViewControl
func createConstraints(view: UIView) {
var constraints = [NSLayoutConstraint]()
constraints.append(view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
constraints.append(view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
constraints.append(view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
constraints.append(view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
NSLayoutConstraint.activate(constraints)
}
And here is the full file of GameViewControlimport UIKit
import SpriteKit
class GameViewController: UIViewController {
		
		private let myView : UIView = {
				let myView = UIView()
				setViewAttributes(view: myView)
				return myView
		}()
		private func addConstraints(){
				 var constraints = [NSLayoutConstraint]()
				//add
constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
//activate
NSLayoutConstraint.activate(constraints)
}
override func viewDidLoad() {
super.viewDidLoad()
#if DEBUG
print ("viewDidLoad")
#endif
if let view = self.view as! SKView? {
getScreenDimensions (screen: &screenDims)
view.addSubview(myView)
addConstraints()
var scene : GameScene!
DispatchQueue.main.async { scene = GameScene(size: CGSize(width: self.myView.frame.width, height: self.myView.frame.width))
scene.anchorPoint = CGPoint(x: 0.0, y: 0.0)
scene.backgroundColor = .clear
scene.scaleMode = .aspectFit
view.isHidden = false
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
view.showsPhysics = true
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
#if DEBUG
print ("GVC viewDidLayoutSubviews")
#endif
myGlobalVars.sceneRect = view.frame
if #available(iOS 11.0, *) {
myGlobalVars.topSafeArea = view.safeAreaInsets.top
myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom
} else {
myGlobalVars.topSafeArea = topLayoutGuide.length
myGlobalVars.bottomSafeArea = bottomLayoutGuide.length
}
}
override var shouldAutorotate: Bool {
#if DEBUG
print ("shouldAutorotate")
#endif
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
#if DEBUG
print ("supportedInterfaceOrientations")
#endif
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
override var prefersStatusBarHidden: Bool {
#if DEBUG
print ("prefersStatusBarHidden")
#endif
return false
}
}
The call to function setViewAttributes does pass the view to a function, and I have verified that that function is working.func setViewAttributes(view: UIView)
{
view.alpha = 0.0
view.frame.size.height = UIScreen.main.nativeBounds.height
view.frame.size.width = UIScreen.main.nativeBounds.width
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .clear
}
I am currently using this code in my GameViewController file to retrieve the boundaries of the safeArea
	 override func viewWillLayoutSubviews() {
				super.viewWillLayoutSubviews()
				let safeAreaInsets = self.view.safeAreaInsets
		}
My concern is that if I were using a UIView (called myView below), I could automatically apply it with this code block and never think of it again.
var constraints = [NSLayoutConstraint]()
constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
}
Is there an equivalent call when I'm doing that for a UIViewController?
Also, from all my reading online many posts have said to use trailing and leading rather than top and bottom. However self.view.safeAreaInsets appears to only have top and bottom.
In GameViewController I do set the safeAreaLayouts. My only problem is that the top and bottom safe areas (iPhone X) are white.
Now I can change them via Main.storyboard. However, am working (or learning) my way to create apps without any storyboards.
Besides, perhaps I may to vary the background colors of the safeAreas.
So was looking for a way to do it with coding. Since I am hear, is there a way to also change the color of the text in the status bar as well?
Am pasting the complete code for GVC, just in case that has something to do with my question.
import UIKit
import SpriteKit
class GameViewController: UIViewController {
		
		public let myView : SKView = {
				let myView = SKView()
				myView.translatesAutoresizingMaskIntoConstraints = false
				return myView
		}()
		private func addConstraints(){
				 var constraints = [NSLayoutConstraint]()
				//add
				 constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor))
				 constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor))
				 constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor))
				 constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor))
				//activate
				 NSLayoutConstraint.activate(constraints)
		 }
		override func viewDidLoad() {
				super.viewDidLoad()
				#if DEBUG
						print ("GVC viewDidLoad")
				#endif
				
//				if let view = self.view as! SKView?
						
						view.addSubview(myView)
						addConstraints()
						var scene : GameScene!
//				var scene = GameScene(size: myView.frame.size)
//				let scene = GameScene(size: myView.frame.size)
						DispatchQueue.main.async { [self] in scene = GameScene(size: myView.frame.size )
								
								scene.anchorPoint = CGPoint(x: 0.0, y: 0.0)
								scene.backgroundColor	 = .clear
								scene.scaleMode				 = .aspectFit
								myView.isHidden					 = false
								myView.ignoresSiblingOrder		= true
								myView.showsFPS							 = true
								myView.showsNodeCount				 = true
								myView.showsPhysics					 = true
								myView.presentScene(scene)
						}
				
		}
		override func viewWillLayoutSubviews() {
				super.viewWillLayoutSubviews()
		}
		override func viewDidLayoutSubviews() {
				super.viewDidLayoutSubviews()
				#if DEBUG
						print ("GVC viewDidLayoutSubviews")
				#endif
				getScreenDimensions (screen: &screenDims)
				if myGlobalVars.safeSceneRect == .zero {
						myGlobalVars.sceneRect = view.frame
						myGlobalVars.sceneRect = myView.frame
				}
				
				if #available(iOS 11.0, *) {
						myGlobalVars.topSafeArea		= view.safeAreaInsets.top
						myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom
				} else {
						myGlobalVars.topSafeArea		= topLayoutGuide.length
						myGlobalVars.bottomSafeArea = bottomLayoutGuide.length
				}
		}
		
		override var shouldAutorotate: Bool {
				return false
		}
		override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
				if UIDevice.current.userInterfaceIdiom == .phone {
						return .portraitUpsideDown
				} else {
						return .all
				}
		}
		override var prefersStatusBarHidden: Bool {
				return false
		}
}
Am currently using Xcode Version 12.1 (12A7403)
About a week ago the App Store tried to update Xcode but went nowhere for hours. The update is dated 10/25
So from a linkI was able to downloaded Xcode 12.1.1 dated 10/30
from https://developer.apple.com/download/more/
According to the Apple website, the download is Xcode 12.1.1 dated 10/30
Now sure which to do, or if there's a way I can backup my current Xcode and it's settings just in case something goes wrong.
Has anyone experienced this as well?
I am trying to create four walls, that would surround the screen.
From GameScene I call
let leftWall = MyEdge(side: Walls.left)
The code below works. But then I cannot add it as a child to GameScene, also I would like to give it an SKPhysicsBody.
My problem is figuring out the super.init. I've tried
super.init(texture: nil, color: .clear, size: CGPath(w: 0, h: 0))
super.init()
But I always get
Type of expression is ambiguous without more context
class MyEdge {
		let yourline = SKShapeNode()
		let pathToDraw = CGMutablePath()
		var color : SKColor
		var startAt : CGPoint
		var endAt : CGPoint
		var colMask : UInt32
		var conMask : UInt32
		var catMask : UInt32
		var name : String
		init(side: Walls){
				let whichWall = side
				switch whichWall
				{
						case .left:
myGlobalVars.backGround!.size.height+1)
								startAt = CGPoint(x: 5, y: 5)
								endAt = CGPoint(x: 5, y: myGlobalVars.safeSceneRect.size.height-5)
								color = .white
								colMask = bodyMasks.gemMask.rawValue
								conMask = bodyMasks.blankMask.rawValue
								catMask = bodyMasks.edgeMask.rawValue
								name = "left"
				}
				pathToDraw.move(to: startAt)
				pathToDraw.addLine(to: endAt)
				yourline.lineWidth = 2
				yourline.path = pathToDraw
				yourline.strokeColor = color
		}
}