sprite-kit

How to assign Keys to SKActions in Swift

拈花ヽ惹草 提交于 2019-12-21 14:06:34
问题 I was hoping someone would be able to help me with this problem. I can't seem to find a way to assign a key to an SKAction for Sprite Kit for the removeActionWithKey method. I have also tried assinging the action to a key in a dictionary but the program didn't recognize the key assignment and thus returned a nil value. Here is what I tried to do: var textureanimation = SKAction.repeatActionForever(SKAction.animateWithTextures(_walkingframes, timePerFrame: 0.1)) var dictionary = ["animation":

Rotating an SKShapeNode along its center

倾然丶 夕夏残阳落幕 提交于 2019-12-21 13:42:25
问题 I have an SKShapeNode (rectangle in this case) which I am trying to rotate along its center. However it is rotating along the screen's bottom left point. Since I cannot set an anchor point for SKShapeNode, how can I achieve my requirement (to rotate the shape along its centre). This is the code I'm trying. let rectangle = SKShapeNode() rectangle.path = UIBezierPath(rect: CGRectMake(view.frame.width/4, view.frame.height/2, view.frame.width/2, view.frame.width/2)).CGPath rectangle.fillColor =

Screen's real size is bigger than what I see

天大地大妈咪最大 提交于 2019-12-21 12:29:37
问题 I'm learning both Swift & SpriteKit. I created new SpriteKit & Swift game project in Xcode 6 and I edited file GameScene.swift . I didn't touch other files. The problem: When the ball bounces around, It's limited by top and down side but when it goes to left or right side it's not limited and goes out but it seems that the right and left limits are there but they aren't on screen edge because ball comes back after a little while. This is my GameScene.swift : import SpriteKit class GameScene:

Delay next action in SKAction.sequence after runBlock occurs (Swift)?

给你一囗甜甜゛ 提交于 2019-12-21 12:17:28
问题 The duration property for moveTo isn't followed when inside a runBlock , allowing the subsequent action in a sequence to get executed immediately when it should only get executed after duration seconds. Code A (sequence properly executed): let realDest = CGPointMake(itemA.position.x, itemA.position.y) let moveAction = SKAction.moveTo(realDest, duration: 2.0) itemB.runAction(SKAction.sequence([SKAction.waitForDuration(0.5), moveAction, SKAction.runBlock { itemB.removeFromParent() }])) Code B

How do I obtain the SKSpriteNode of an item created through SpriteKit Editor?

流过昼夜 提交于 2019-12-21 11:01:14
问题 I have created a fairly simple (at this point, experimental) "game" in XCode using SpriteKit (with Objective-C). I know how to manually create a SKSpriteNode object and add it to the SKScene - but I am kind of trying to do the opposite - where I created the sprite inside the XCode SceneKit GUI itself (and gave it a name), now I want to retreive it in my code. In prior experience with XCode, you would do this by declaring a @property UIOutlet [etc] and then connecting it as a referencing

checking if an SKNode is running a SKAction

谁说我不能喝 提交于 2019-12-21 09:29:17
问题 How can I check whether a SKNode is already running an action before running an action on it? I want to be able to do something like... if (![mySprite isRunningActions]) { [mySprite runAction:action]; } If there is no built in way I'm thinking of creating a new BOOL property for holding the action state. 回答1: Look at using named actions using any of the SKAction key-based methods. So you would instead run your action using the named equivalent to runAction: which is runAction:withKey: . If an

SpriteKit SKView showsFields memory usage

泄露秘密 提交于 2019-12-21 07:25:30
问题 I am curious about when showsFields is turned on, the memory usage increase extremely fast? It can growth up to 500MB under 30 seconds. If my mac only have 8GB of RAM, I probably have less than 8 minutes to debug before memory warning, it will be worst when debug on real device. The screenshot below is tested from a real device (iOS 9.2). You can quickly try it by creating a SpriteKit project and turn showsFields on in viewDidLoad() method inside the view controller. skView.showsFields = true

How can I apply an angular impulse to a Sprite Kit node based on a pan gesture velocity

本秂侑毒 提交于 2019-12-21 06:27:21
问题 What I'm looking to do here is to spin a SKSpriteNode around its anchor point and have its speed and direction match a pan gesture. So if my pan gesture is clockwise around the sprite then then sprite spins clockwise. The problem I have with my code is that it works great for pans below the sprite from left to right/right to left, but not at all when I try and pan vertically and it makes the sprite spin the wrong way if I pan above the sprite. Here's what I've got so far - let windmill =

How to spawn Multiple of the same SpriteNode at once?

大城市里の小女人 提交于 2019-12-21 06:01:11
问题 So I have 3 different obstacles which spawn randomly and get removed after 3 seconds, but if for example Obstacle1 is already spawned and the random Number tells the program to spawn another Obstacle1, I get a Error that says "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent" heres the code of Obstacle1, the other two are almost the same just the names are different: func createObst1() { self.addChild(obst1)

Is it possible to have a Twitter / Facebook share button in a sprite-kit game?

蹲街弑〆低调 提交于 2019-12-21 05:57:08
问题 I'm completely lost, all the tutorials I've found have been for iOS 6 apps with Storyboards. My question is if you can have a twitter or facebook sharing feature in a sprite-kit game? If so what is the best way to go about adding it? Alot of the tutorials I've read over use viewcontrollers but sprite-kit uses scenes so I'm a bit confused. Thanks. 回答1: Here is an answer for twitter. Your Welcome! 1) import the Social framework under the Build Phases tab then Link Binary with Libraries. Put