sprite-kit

Touch detection doesn't work on simulator for iOS 9

北城以北 提交于 2019-12-11 03:34:00
问题 I've updated Xcode to Xcode 7. Then my Swift project to Swift 2. At last I removed removed all warnings. First scene display few SKLabel and few SKSpriteNode . Using iOS Simulator, touch detection doesn't work under iOS 9 but is ok on iOS 8. A breakpoint put on touchesBegan method show this method is not called. override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { // Breakpoint is set here } EDIT Removing these messages does not solve anything. Console display

Why is my node flashing? (Making a score in swift)

别等时光非礼了梦想. 提交于 2019-12-11 03:33:44
问题 I have placed my scoreNode as a child of the randomly chosen animated balls my character has to avoid and the scoreNode is flashing (when I set it to a visible blue colour) and too many contacts are counted between the character and the scoreNode. So basically I think it is only generating the scores at each animation frame rather than just being a constant node. How do I change this to where it picks up the score normally and the node stops flashing and picking up too many collisions? p.s. I

Loading animation while passing between scenes

和自甴很熟 提交于 2019-12-11 03:28:32
问题 I am making an iOS game using Swift. At the menu (Menu is a SKScene), I have a button that starts the game, let's call it 'start button'. When I hit the start button, application freezes and loads the gameplay (gameplay is a SKScene), then transition animation runs and gameplay begins. But instead of the freeze of the application, I want a rotating loading circle while application loads the gameplay. How can I do that? Ask me if there is something not clear... func loadingScreen(scene:SKScene

How could I skew/shear a sprite via SpriteKit like Cocos2D?

心已入冬 提交于 2019-12-11 03:21:49
问题 In Cocos2D-x, CCNode class provides "skewX" & "skewY" to let me do some distortion of the sprite, however, I fail to find similar mapping in SKNode of SpriteKit. My game uses Flash to port skeleton animations, in which the configs of positioning, scaling, rotation and shearing of sprites would be decomposed into game-engine's digestive. Except shearing, all other configs do have solutions to be done in SpriteKit. 回答1: No you can't. SKNode doesn't have skew* properties. And SKShader allows to

How to suppress a “SpriteKit Texture Atlas Generator Warning”?

不想你离开。 提交于 2019-12-11 03:15:52
问题 Xcode is reporting the following warning: "SpriteKit Texture Atlas Generator Warning Splitting 'images.atlas' into 2 texture atlases due to input texture dimensions." Although I will modified my images in the future to avoid SpriteKit from generating this warning, I would like to temporarily suppress this warning using some pragma directives. Does anyone know the warning flag to use to suppress this warning using code like the following? #pragma clang diagnostic push #pragma clang diagnostic

How do I make a SKSpriteNode that does not respond to touch if it's pixels are transparent?

我的梦境 提交于 2019-12-11 02:52:46
问题 I am creating a game for iOS using sprite kit written in swift. I have a bunch of SKSpriteNode on a screen that can be dragged around. They are various shapes such as a person, an apple, a book etc. The problem is, say the person is in front of the apple but you can see the apple behind the person through the transparent pixels in the persons image (png). When you go to touch the apple to move it, the person gets selected because of those transparent pixels instead of the apples. How do I

SpriteKit didBeginContact called but not didEndContact

这一生的挚爱 提交于 2019-12-11 02:48:57
问题 I have the following code, the didBeginContact(contact:) method is called but not didEndContact(contact:) . // FIXME: This is a workaround until class vars are supported let sharedContactHandler = ContactHandler() class ContactHandler: NSObject, SKPhysicsContactDelegate { class var sharedHandler: ContactHandler { get { return sharedContactHandler } } func didBeginContact(contact: SKPhysicsContact) { let bodyA = contact.bodyA let bodyB = contact.bodyB NSLog("Began contact") ... } func

Create random CGPoint with Swift

社会主义新天地 提交于 2019-12-11 02:37:29
问题 So, I'm trying to develop a simple game written in Swift, but I'm having trouble doing a pretty simple thing. I can't manage to create a random CGPoint... When using arc4random, a compiler error shows up telling me that I can't use Int32 in a CGPoint. So, Is there any way to do this? Any workaround? Thanks! 回答1: hi what about constructing an Int? Int(arc4random()) e.g. var p = CGPoint(x:Int(arc4random()%1000),y:Int(arc4random()%1000)) 回答2: can also maybe make use of Swift's extensions of base

Using Navigation controller for a start screen ios

若如初见. 提交于 2019-12-11 02:05:48
问题 I've come to the point where I need to make a start screen for my game made with sprite kit. I can not get it to show with any of the code and tutorials I have read and watched. I want to use a navigation controller/view controller to begin at the start screen and have it linked to my app but I am not sure how to link my game's code to the view controller. Using a navigation controller, how would I drag it into my game's code as a @IBAction declaration? Thank you. Edit with current code:

Programmatically create constrained region of physics, SpriteKit

Deadly 提交于 2019-12-11 01:34:14
问题 I would like two regions, as shown in the image below, where the yellow region is to contain sprites. For example I'd like to have balls in the yellow region bouncing and reflecting off the boundaries of the yellow region. How can I programmatically do this without using an sks file? 回答1: You create an edge based physics body using the +bodyWithEdgeLoopFromRect: override func didMoveToView(view: SKView) { //Setup scene's physics body (setup the walls) physicsBody = SKPhysicsBody