sprite-kit

Swift Spritekit I detect a collison but it reads the collision mulitple times

*爱你&永不变心* 提交于 2019-12-19 09:29:03
问题 AppImage I have a wall of 4 rectangles that are different colors, to pass through the wall the color of the ball has to match that of the rectangle on the wall. The ball will pass through the wall, and a new wall will appear. However, when I detect this collision I get multiple collision readings. I have tested this by printing dead or alive, and it prints both or more many times. func didBegin(_ contact: SKPhysicsContact) { if let nodeA = contact.bodyA.node as? SKShapeNode, let nodeB =

Does SpriteKit apply physics if I modify the position and rotation of a SKSpriteNode directly without an SKAction?

痴心易碎 提交于 2019-12-19 09:23:27
问题 For example if I want to do my own custom animation and move an SKSpriteNode every frame programmatically by x += 10 , will Sprite Kit still apply physics correctly or must I always use SKAction? 回答1: Manually moving a node with a physics body is possible regardless of how or when you do it. But in any case it's not recommended since it can adversely affect the physics simulation. The node (view) could be out of sync with the position of the body for 1 frame, and you might move the body into

Delay when unhiding UIButtons after presenting SKScene?

别说谁变了你拦得住时间么 提交于 2019-12-19 08:39:07
问题 I have encountered a delay/pause that I was not expecting and the reason so far has me scratching my head. I have a simple game setup where the UIViewController shows a number of UIButtons [PLAY GAME] [VIEW SCORES] etc. which in turn present a different SKScene My problem is that when I try and set the visibility of these buttons to visible (perviously set to hidden in viewDidLoad ) from the UIViewController they take about 5 seconds to actually show. @implementation ViewController - (void

UIPanGestureRecognizer in SKScene

一曲冷凌霜 提交于 2019-12-19 05:37:25
问题 I've been experimenting with UIGestureRecognizers and the new SKScene/SKNode's in SpriteKit . I've had one problem, and I got close to fixing it but I am confused on one thing. Essentially, I have a pan gesture recognizer that allows the user to drag a sprite on the screen. The single problem I have is that it takes ONE tap to actually initialize the pan gesture, and then only on the SECOND tap on it works correctly. I'm thinking that this is because my pan gesture is initialized in

no designated init for SKShapeNode(circleOfRadius: radius)

非 Y 不嫁゛ 提交于 2019-12-19 05:11:54
问题 I'm trying to create a subclass of SKShapeNode in swift as SKShapeNode(circleOfRadius: radius) but there is no designated init for it. Anyone have any workarounds or info about why? I'm not sure if this is a bug or intentional. I found this video demonstrating a workaround for SKSpriteNode but its not working for me. https://skillsmatter.com/skillscasts/5695-how-to-subclass-a-skspritenode Overall i am trying to make a subclass for an SKShapeNode that i can then subclass from again to have

Sprite Kit animateWithTextures lags

ぃ、小莉子 提交于 2019-12-19 04:22:37
问题 I'm using texture atlases in my Sprite Kit game. I'm creating SKTextureAtlas object and store it's textures in array for each animation. So when I need some animation on my hero I call animateWithTextures sending it the corresponding array. There are some lags when I start animations. Is there some way to start animation smoothly? 回答1: I am sure there are few ways to get around this. What you need to do is to preload an atlases before your gameplay actually start. Just show a loading screen

Bounce rays with enumerateBodies alongRayStart

非 Y 不嫁゛ 提交于 2019-12-19 04:05:50
问题 I want to trace the path where a bullet will move in my SpriteKit GameScene. I'm using "enumerateBodies(alongRayStart", I can easily calculate the first collision with a physics body. I don't know how to calculate the angle of reflection, given the contact point and the contact normal. I want to calculate the path, over 5 reflections/bounces, so first I: Cast a ray, get all the bodies it intersects with, and get the closest one. I then use that contact point as the start of my next reflection

SpriteKit support multiple device orientations

醉酒当歌 提交于 2019-12-19 03:31:20
问题 I have a SpriteKit game which I want to support all orientations. Right now when I change the orientation, the node doesn't keep its position. I use the SKSceneScaleModeResizeFill for scaling, because it will keep the right sprite size. When I start the game, the game player is positioned in the mid screen like this: Then when I rotate the device, the position becomes like this: Here is my view controller code: - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; // Configure the

How to create an alpha mask in iOS using sprite kit

瘦欲@ 提交于 2019-12-19 03:18:12
问题 The effect that I am trying to achieve is having a circle of light in an area of darkness. The effect is similar to that in pokemon games, when you are in a dark cave and only have limited vision surrounding you. From what I have tried and read, I have been unable to create a mask over nodes in sprite kit that has alpha levels. The masks I manage to create all have a hard edge, and basically just crop. Reading on the apple developer page about the SKCropNode, which has the maskNode property,

“Tap To Resume” Pause text SpriteKit

可紊 提交于 2019-12-19 02:52:30
问题 I know SpriteKit already handles pausing the game when the app enters the inactive state but what I'm trying to do is add a SKLabelNode "tap to resume" when the app re-enters the active state. Right now it's calling my functions correctly and pausing the game, but the text is not showing. AppDelegate.swift func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary