I have multiple images that at various times I need to replace a target image for a SKSpriteNode.
Each of these multiple images has a different size.
The target SKSpriteNode has a fixed frame that I want to stay fixed.
This target is created via:
myTarget = SKSpriteNode(imageNamed: “target”)
myTarget.size = CGSize(…)
myTarget.physicsBody = SKPhysicsBody(rectangleOf: myTarget.size)
How do I resize each of the multiple images so that each fills up the target frame (expand or contract)?
Pretend the target is a shoebox and each image is a balloon that expands or contracts to fill the shoebox.
I have tried the following that fails, that is, it changes the size of the target to fit the new image .. in short, it does the exact opposite of what I want.
let newTexture = SKTexture(imageNamed: newImage)
let changeImgAction = SKAction.setTexture(newTexture, resize: true)
myTarget.run(changeImgAction)
Again, keep frame of myTarget fixed and change size of newTexture to fit the above frame ..
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Error = Device orientations are not supported in Mac Catalyst processes
Got this error when selecting the Destination = "My Mac (designed for iPad".
I tried using the following Code Snippet in my GameViewController, but it did not work. Can anyone provide some guidance?:
#if os(iOS) && !targetEnvironment(macCatalyst)
// for rotation Landscape <-> Portrait = iOS,
// but *not* for Mac (built for iPad)
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
showScene()
} // viewDidLayoutSubviews
#endif
12.9 inch iPad Simulator not presenting SpriteNodes correctly for Xcode
When I generate my SKScene, I use
ourScene.scaleMode = .aspectFill
I then display several SKShapeNodes, e.g.,
let roomWidth = UIScreen.main.bounds.width
let roomHeight = UIScreen.main.bounds.height
let circleRadius = 30.0
itsStatusNode = SKShapeNode(circleOfRadius: circleRadius)
let circleOffsetX = 95.0
let circleOffsetY = 70.0
let circlePosX = roomWidth/2 - circleRadius - circleOffsetX
let circlePosY = roomHeight/2 - circleRadius - circleOffsetY
itsStatusNode.position = CGPoint(x: circlePosX, y: circlePosY)
toScene.addChild(itsStatusNode)
The above Code works for all Xcode Simulators:
iPad (10th Generation)
iPad Air (5th Generation)
iPad Pro (11 inch) (4th Generation)
iPad Mini (6th Generation)
except the iPad (12.9 inch )(6th Generation)
For example, these work for all except the 12.9"
(landscape)
circleOffsetX = 95.0
circleOffsetY = 70.0
(portrait)
circleOffsetX = 70.0
circleOffsetY = 95.0
For just the 12.9" these work
(landscape)
circleOffsetX = 190.0
circleOffsetY = 145.0
(portrait)
circleOffsetX = 150.0
circleOffsetY = 190.0
I have seen other reports that point other errors out for just the 12.9 inch Simulator.
Or, is this one of many examples when I have to upload the App to a real Device such as my iPad or Apple TV?
FWIW, I only have a iPad Mini, not the 12.9 inch version
As always, thanks bunches for just reading this.
Can you access the objects in a struct from outside the struct?
So far I have a group of HStacks and VStacks whose embedded objects are all Images(“name”).
By definition these Images are fixed in terms of their .position and .size for example.
Can I dynamically access these embedded objects from outside the struct?
In short, move them?
.. or include a Node so I could change its color?
All changes made from Swift outside the struct?
Why does orient Path = true cause the sprite node to rotate CW when the path is horizontal?
Here's just one example:
let trainAction = SKAction.follow(
trainPath.cgPath,
asOffset: false,
orientToPath: true,
duration: 0.1)
myTrain.run(trainAction.reversed())
I have myTrain.zRotation = 0.0
myTrain is a simple locomotive,trainPath = the railroad tracks
Docs state with orientToPath: true, that the Node will always orient itself such that it's facing the UIBezierPath.
To me, facing means that the wheels of the locomotive are facing the BezierPath (= trainPath)
Apparently I am wrong in this interpretation ... if so, what is the correct interpretation?
FYI, comparing the snapshot of my initial placement of the locomotive on the tracks using .position with what happens after I start moving the locomotive:
These snapshots indicate that facing means that the nose of the locomotive is facing the BezierPath (= trainPath).
If true, how do I eliminate that CW rotation?
I know that this is not a coding question and I have posted on the regular Apple Forum and have been working with the 800 Tech Support folk for 4 months.
I am in a world of hurt.
Have ATV + Samsung TV + external soundbar.
All software versions are current
NO Cable box (direct input). 4 months ago I had Cable box = zero problems.
With Samsung on and ATV off, stereo = Dolby 5.1 sounds great.
With ATV also on, no stereo.
I can use Siri remote to activate stereo until I change to a new movie. ATV then reverts to mono = PCM
One Tech Support lady said to just not watch multiple movie.
?$@!*+^?
I have spoken with engineers at Samsung and Sonos (soundbar). Both say my cabling is correct = 1 cable from soundbar to HDMI Arc on TV + 1 cable from ATV to another HDMI port on TV.
Another Tech Support folk said to connect ATV to soundbar. Soundbars don’t have gobs of HDMI ports, the TV does.
?!$@*^+%#
I have spoken with Apple Tech Support with zero help for 3-4 months.
I think I have been a good soldier. But it is time for real results.
Please help
How to ensure current SKScene has fully loaded before engaging it with the GamePad Controller?
MAJOR REWRITE FOR THE SAKE OF HOPEFULLY (?) INCREASED CLARITY
The problem is this = when stopping sound is involved when I do switch SKScenes, if I press the buttons of the GamePad Controller (which cycle thru these other SKScenes) too fast, the movement of the Game Pieces fails to resume when I return to the Game Scene after the above cycling.
This problem occurs only with the os(tvOS) version, but not with the iPad version. And the reason for this distinction is that each SKScene for the iPad has to fully load due to the fact that the button I press to switch SKScenes is at the top-left corner of the iPad -- so, by definition, by the time I have access to this button, the current SKScene has fully loaded.
By definition, there is no such button for os(iOS).
Given this button’s absence, I need the Swift version of jQuery’s
$(document).ready (function() {.
Any help will be appreciated to the rafters ...
What is the best way to change just one image in an App Connect Build while waiting for review?
Zero code changes, just one Image Asset.
Please tell me I do not have to delete Build and start from scratch! for one lousy image!
Cannot find how App Connect shows "Unresolved Issues" on an Approved + Uploaded App.
Would appreciate some hints. Thanks in advance!
Cannot look at contents of file in Print Queue with Sonoma
Before Sonoma, after I selected print in a application, e.g., Word, I could double click on the document stored in the Print Queue and the pages would be displayed.
With Sonoma, cannot see file contents??
One last thing pertaining to this Print Queue =
I can't delete any of the accumulated "Completed" Jobs .. menu item to delete selected Jobs is dimmed??
Can you access the objects in a struct from outside the struct?
So far I have a group of HStacks and VStacks whose embedded objects are all Images(“name”).
By definition these Images are fixed in terms of their .position and .size for example.
Can I dynamically access these embedded objects from outside the struct?
in short, move them ?
Do I really have to reset position and size of SKSpriteNodes with every rotation between landscape and portrait layout??
I've done that and it works .. but this seems to be overkill that the writers of Xcode internally compensated for .. vs. having the individual programmer having to do it.
I have a getGameParms() which resets positions based on:
#if os(iOS) && !targetEnvironment(macCatalyst)
func getGameParms() {
let roomRect = UIScreen.main.bounds
roomWidth = roomRect.width * roomScale
roomHeight = roomRect.height * roomScale
if (thisSceneName == "GameScene")
{
if UIDevice.current.orientation.isLandscape {
// changes here
}
else {
// changes
}
} // if (thisSceneName == "GameScene")
} // getGameParms
#elseif os(tvOS)
func getGameParms() {
let roomRect = UIScreen.main.bounds
roomWidth = roomRect.width * roomScale
roomHeight = roomRect.height * roomScale
if (thisSceneName == "GameScene")
{
// other changes here
}
} // getGameParms
#endif
Again, the burdensome changes are done .. but are they really necessary?
As an alternative, I have called getGameParms() just once within my viewDidLoad() and the results are not correct.
For example, I place one SKSpriteNode at the very bottom of the UIScreen and it does not stay there with UIDevice rotation. I also size it horizontally such that it expands to the full width of the UIScreen. Rotation destroys that. if getGameParms() is called only once as just described.
Some explanation as to why would be appreciated.
How to attach a struct to the main GameViewController?
This struct occupies the top half of the main ViewController.
The goal is to have this struct be part of the main GameViewController and not in separate UIHostingController.
SO, when I rotate the main SKScene for example the struct also rotates OR when I switch SKScenes both the top-half struct and the bottom-half switch together because they are one SKScene.
The programmer who invented HStacks and VStacks is a blooming genius … but I need to avoid what I have now which is the HStack VStack combo closing and then its neighbors in the main SKScene closing.
Here are the essential code segments - all in my GameViewController:
Declared at the top:
var useGSO = false
var gsoChildVC: UIViewController! // = UIHostingController
override func viewDidLoad() {
showScene()
/*
"gso" = "Game Static Objects"
*/
if useGSO {
// create a UIHostingController and extract a rootView for later processing
gsoChildVC = UIHostingController(rootView: GameStaticObjects())
}
} // viewDidLoad
Within my showScene():
func addGamePieces(toScene: SKScene) {
if thisSceneName == "GameScene" {
// various SKSpriteNodes
//
// STATIC People, Animals and Buildings
// are now added to the top of our SKScene
//
addGSOChild(toScene: toScene)
} // if thisSceneName == "GameScene"
else {
removeGSOChild()
}
} // addGamePieces
func addGSOChild(toScene: SKScene) {
// gsoChildVC = nil *if* useGSO = false
guard gsoChildVC == nil else {
let gsoParentVC = self // parent = us = GameViewController
// default value
// gsoChildVC.view.translatesAutoresizingMaskIntoConstraints = true
/**/
let sameWidth = gsoParentVC.view.bounds.width
let newHeight = 0.5 * gsoParentVC.view.bounds.height
let boundsWithNewBottom = CGRectMake(0.0, 0.0, sameWidth, newHeight)
gsoChildVC.view.frame = boundsWithNewBottom
/**/
// first, add the view of the hild to the view of the parent
gsoParentVC.view.addSubview(gsoChildVC.view)
// then, add the child to the parent
gsoParentVC.addChild(gsoChildVC)
// notify the child ViewController that we're finished
gsoChildVC.didMove(toParent: gsoParentVC)
return
}
} // addGSOChild
func removeGSOChild() {
// gsoChildVC = nil *if* useGSO = false
guard gsoChildVC == nil else {
// First, remove the Child from its Parent
gsoChildVC.removeFromParent()
// Then, remove the Child's view from the Parent's
gsoChildVC.view.removeFromSuperview()
return
}
} // removeGSOChild
As stated at the top of this OP, the HStack and Stack code appears great .. but the UIHostingController is distinct from my GameViewController. As a direct result, such operations as switching SKScenes is done in 2 halves - (1) the HStack and Stack top half and (2) whatever non-struct stuff appears below it.
If I switch SKScenes, I want both halves to switch as one entity.
FWIW, the struct that contains the HStack and Stack code is outside the GameViewController class as suggested by Apple.
and as specified above, I call:
gsoChildVC = UIHostingController(rootView: GameStaticObjects())
within my viewDidLoad() method.
I would love some basic guidance here as to what basic error I am making.
How do I change just the starting point of an existing UIBezierPath? .. and leave all other points the same?
I have definitely seen many posts on how to do this .. honestly, I just do not understand many of them
My existing path has one .move(to:) and many .addLine(to:)
My goal is:
(1) replace the .move(to:) with .addLine(to:) and then
(2) change one of the .addLine(to:) with .move(to:)
All other CGPoints stay the same.
In order to get the new starting point, I set:
savedPathPoint = myPath.currentPoint
when I stop the following motion.
At some point, I want to resume this following motion with the new starting point = savedPathPoint via
myPath.move(to: savedPathPoint)
let myAction = SKAction.follow(
myPath.cgPath,
asOffset: false,
orientToPath: true,
duration: 0.1)
mySprite.run(myAction)
When I look at the above problem description, it really appears simple.
Nevertheless, its implementation alludes me.
Thanks bunches in advance for any hints whatsoever.
How do I change a UIBezierPath.currentPoint to a SKSpriteNode.position?
Here are the appropriate code snippets:
func createTrainPath() {
let startX = -tracksWidth/2,
startY = tracksPosY
savedTrainPosition = CGPoint(x: startX, y: startY!)
trackRect = CGRect(x: savedTrainPosition.x,
y: savedTrainPosition.y,
width: tracksWidth,
height: tracksHeight)
trainPath = UIBezierPath(ovalIn: trackRect)
trainPath = trainPath.reversing() // makes myTrain move CW
} // createTrainPath
Followed by:
func startFollowTrainPath() {
let theSpeed = Double(5*thisSpeed)
var trainAction = SKAction.follow(
trainPath.cgPath,
asOffset: false,
orientToPath: true,
speed: theSpeed)
trainAction = SKAction.repeatForever(trainAction)
createPivotNodeFor(myTrain)
myTrain.run(trainAction, withKey: runTrainKey)
} // startFollowTrainPath
So far, so good (I think?) ...
Within other places in my code, I call:
return trainPath.currentPoint
I need to convert trainPath.currentPoint to myTrain.position ...
When I insert the appropriate print statements, I see for example:
myTrain.position = (0.0, -295.05999755859375)
trainPath.currentPoint = (392.0, -385.0)
which obviously disqualifies a simple = , as in:
myTrain.position = trainPath.currentPoint
Since this = is not correct, what is ?
After more investigation, my guess is that .currentPoint is in SKSpriteNode coordinates and .position is in SKScene coordinates.