Am trying to make a game, where I drag gems around.
The hierarchy is:
GameScene (this is the view controller)
gemBase, which holds the gems (light grey) SKSpriteNode
gems SKSpriteNode
The gems are children of gemBase, which is a child of GameScene.
When the gemBase is at 0,0 everything works fine when I drag the gems. They are in the same place I am touching the screen. But I want to offer a left-handed feature, where I offset the gemBase to the rightsize of the screen. All gems automatically move with the base so I don't need to recalculate their positions.
But then, when I try to move the gems, they are offset to the right of where I am touching the screen. They are offset by as much as I move the gemBase.
Below is my only code where I handle touchesMoved (in GameScene)
If you're having problems visualizing what I am describing, the screen shot is at:
http: // 98.7.37.117/ss.gif
Do I have to convert the touch.location?
override func touchesMoved(_ touches: SetUITouch, with event: UIEvent?){
guard touches.first != nil else { return }
if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}
if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {
let touchLocation = touch.location(in: self)
node.moved = true
node.position = touchLocation
node.isMoving = true
node.inSlot = false
//addTrailToTwinkle(theNode: node)
}
}
Post
Replies
Boosts
Views
Activity
I am using the SQLite wrapper for Xcode. I got it from the link below and did install it.
But was hoping there would better documentation, or tutorials out there for it. Am new enough at Swift and its syntax. Whatever can make this easier for me would be a big help.
https: //git.pado.name/reviewspur/ios/tree/fd2486cf91e422e2df8d048ffd2d40ea89527685/Carthage/Checkouts/SQLite.swift/Documentation#building-type-safe-sql
My app needs a database and I would like to use SQLite.
Other than
using import SQLite3
and
adding libsqlite3.tbd in the Build Phase
Are there any other files I need to copy or import into my project?
Xcode updated, and when it first asked, allow Xcode to access to local files, I said No by mistake.
Now I don't know how to change that?
I just keep getting Could not open workspace file at
I can open the project using File-Open-Project. But I can't open from the Start Window.
I wanted to use a png image to create a pattern for an SKSpriteNode. Supposedly:
Pattern images are not supported via UIColor in SpriteKit
So I am supposed to use an .fsh file for shading. The thing is, can I create such a file from an image? Everywhere I've looked only show's mathematical methods for creating those files.
I hope this is something that is possible
I have an SKScene, where I use an SKSpriteNode as the background. While the work I do below to make it fit to scale isn't much, I wondered if Swift provided a method or property that would do the same?
From my GameScene
override func didMove(to view: SKView){
super.didMove(to: view)
self.backgroundColor = .clear
let ratio = self.size.height / background.size.height
background.size.height *= ratio
background.size.width *= ratio
background.anchorPoint = CGPoint(x: 0.0, y: 0.0)
background.zPosition = -1
addChild(background)
physicsWorld.contactDelegate = self
self.isHidden = true
From my main ViewController, where I create the GameScene
let scene = WheelScene(size: myView.frame.size)
scene.anchorPoint = CGPoint(x: 0.0, y: 0.0)
scene.backgroundColor = .clear
scene.scaleMode = .aspectFit
wheelScene = scene
mainView = myView
myView.presentScene(wheelScene)
My code is compartmentalized over many files, so I hope I can describe this easily.
I have a path that goes from point A to point B
I place an SKSpriteNode at point A and execute:
iconPath[0] = the path
SKAction.follow(iconPath[0], asOffset: false, orientToPath: false, duration: 1))
I execute that SKACtion and as I expected, my SKNode goes from point A to point B. Fine.
I'm not sure how to reverse it, I assumed from the dox that calling that same SKAction as is, would make the SKNode go from point B to A.
I already know how to run multiple animations on the same SKSpriteNode at once:
createPaths()
let myIcon1 = MyIcon(wIcon: "screen", iSize: iSize)
let move = SKAction.follow(iconPath[0], asOffset: false, orientToPath: false, duration: 1)
let shrink = SKAction.resize(byWidth: -iSize.width/2, height: -iSize.width/2, duration: 1)
let blur = SKAction.fadeAlpha(to: 0.6, duration: 1)
let group = SKAction.group([shrink, move, blur])
myIcon1.run(group)
But I have two more icons I would like to animate at the same time.
Granted, with just 3 icons total I can't see any lag if I do something like this:
myIcon1.run(group1)
myIcon2.run(group2)
myIcon3.run(group3)
But surely there is a proper way to do this?
I have a scene on top of the main ViewController. While that scene will have objects in it, I'd like the background to be clear.
However
myView.backgroundColor = .clear
myView.allowsTransparency = true
produces a black box.
Am I missing some step?
This was something I needed so much help with in this post
https://developer.apple.com/forums/thread/666997
I want to add a user defined setting. As I did (from the answer in the previous post, I made sure I was adding in SWIFTACTIVECOMPILATION_CONDITIONS
I added MYDEBUG01, which does not work. This is in Xcode 12.4
I put up both projects in a picture, the one where it does work is the bottom one, MYSCENES. This was in Xcode 11.x
The screens do look a little different, but can't figure out where my error is.
Here is the screenshot
http:// 98.7.37.117/index.html
I just upgraded to Xcode 12.4, created a project using the "app" template, without SwiftUI, I chose Storyboard instead.
I placed a small image on the LaunchScreen.storyboard, and an NSLog output in my ViewController.
When I run the app on the simulator, the LaunchScreen does not, show, and I do get my NSLog output. So I know the app is running. When run this bare app on my physical iPhone X...I do get the launch screen.
So I opened a game app I started under Xcode 11.x. It will show the LaunchScreen on both simulator and my device.
I've checked that Launch screen interface file base name is set to LaunchScreen in Info.plist. It's also set under App Icons and Launch Images.
Is this some bug?
Haven't touched Xcode since it upgraded to 12.4. Just started a new app, which I planned to create without storyboards. But the default files I am used to deleting or manipulating aren't there anymore. I don't even see AppDelegate.swift.
So did Xcode 12.4 get rid of "storyboards" by default? And if so, where do I go to relearn how to start?
Thanks.
When I'm dealing with touchesBegan, moved, etc. I am able to loop through every item at the CGPoint where the action occurred. So obviously I am dealing with everything through my GameScene.
Now when working with UITapGestureRecognizer, I can't seem to come up with the code that would tell me if there are multiple items at the point of tapping (single tap only). It's not that I want that to happen, but I fear my code may crash if it does occur.
Should UITapGestureRecognizer be handled by each SKNode that uses it? Or is there a code solution where I can handle it all through GameScene?
Here is how I deal with touches_:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
				guard let touch = touches.first else { return }
				let location = touch.location(in: self)
				let touchedNodes = self.nodes(at: location)
				for theNode in	touchedNodes{
						if let node = theNode as? MyBall {
.......my code,......
								}
						}
				}
			}
And here's how I handle UITapGestureRecognizer, yet unable to figure out code to see if there's more than one SKNode:
@objc func tappedView(_ sender:UITapGestureRecognizer) {
		if sender.state == .ended{
				let point : CGPoint = sender.location(in: self.view)
var post = sender.location(in: sender.view)
				post = self.convertPoint(fromView: post)
				if let touchNode = self.atPoint(post) as? Ball{
......my code.......
				}
		}
}
My app is very simple. Using all the touchesFunctions, I can drag a ball around the screen
I'd also, like the user to be able to tape the ball, then tap where to place it, hence no dragging. Just tap to select the ball, then tap where to send it.
I added UITapGestureRecognizer to my code.
My problem is that with a tap, touchesBegan and touchesMoved are also triggered. The heavier the user taps, the more touchesMoved are registered. In one test I was able to do an intended tap, and still got 15 touchesMoved before the Tap.
Is there an iOS property that can somehow help me? Because the only other choice I see is writing ugly code that has to compare time so a selection
My problem is that I don't get the tap trigger till the end.
So I can write code to detect time differences, or something else horrendous, or maybe there's a property that can help?
If I have the following SKActions I want done:
let spinAction = SKAction.rotate(byAngle: 360, duration: 003)
let moveAction = SKAction.move(to: CGPoint(x: origNP.x, y: origNP.y), duration: 0.3)
let setFlags = SKAction.run { moveThis.inSlot = true;
		moveThis.isMoving = false; moveThis.inSlot = true}
I know I can either run them in sequence:
let sequence = SKAction.sequence([spinAction, moveAction, setFlags])
or all at once as a group
let group = SKAction.group([spinAction, moveAction, setFlags])
But what if I need to call other sequences, or just reset flags after the sequence or group method is done?
Do they have some sort of notifiers after completion?