sprite-kit

Velocity meters per second or pixels per second?

痞子三分冷 提交于 2021-01-29 04:34:02
问题 apple documentation gives a physics bodies velocity as in meters per second. If this is true is there a relationship between pixels and meters? and if there is, what is it? or is this an error in the documentation and its really pixels per second? 回答1: I wrote a small program to try to work this out and got an answer of 135 points to the metre. https://stackoverflow.com/a/37523818/1430420 Edit: Here is the program for anyone to check to see if my maths is off // // GameScene.swift //

Detect long touch in Sprite Kit

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 21:03:20
问题 I have a node in a SKScene that I am moving as per the users touch. Basically, this character should also be trying to follow the users finger (Assuming the finger is on the screen). I currently have it implemented as so, which works fine: override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { let touch = touches.first as! UITouch player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1)) } override func touchesMoved(touches: Set<NSObject>, withEvent

Detect long touch in Sprite Kit

泄露秘密 提交于 2021-01-28 20:36:23
问题 I have a node in a SKScene that I am moving as per the users touch. Basically, this character should also be trying to follow the users finger (Assuming the finger is on the screen). I currently have it implemented as so, which works fine: override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { let touch = touches.first as! UITouch player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1)) } override func touchesMoved(touches: Set<NSObject>, withEvent

Shader with SpriteKit only register alpha for black color

半城伤御伤魂 提交于 2021-01-28 19:47:05
问题 I'm starting to use shaders with SpriteKit on iOS. And it's quite a journey... Right now I have some strange behaviour. I was trying to create a outer glow shader. So my goal was to modify the color and alpha of transparent pixel to be less transparent and with a specific color, and I was unable to achieve the transparence level of it. So I dug and created the following: I loaded a texture with different alpha levels (mostly 0 and 1) into an SKSpriteNode Applied the shader. The shader is the

Export SKTexture to a UIImage with alpha channel

天大地大妈咪最大 提交于 2021-01-28 19:43:44
问题 I would like to be able to export my SKTexture to an external image file. I have been able to achieve this using the following code. However it suffers from the critical flaw that the alpha channel is ignored even thoough the view is not opaque and all background colours are set to clear. - (void)export:(CGRect)bounds texture:(SKTexture *)texture path:(NSString *)path{ UIGraphicsBeginImageContextWithOptions(bounds.size, NO, [UIScreen mainScreen].scale); SKView *view = [[SKView alloc]

How can I get SKEmitterNode to work in SwiftUI?

徘徊边缘 提交于 2021-01-28 00:35:43
问题 I'm trying to update the colour of an SKEmitterNode within a UIViewRepresentable . The hue value is passed in from the state on the parent View, and the emitter colour should update when the hue value in the parent state updates. It initially displays, and although it updates on the first call to updateUIView it does not respond to any subsequent calls, even though the function definitely gets called with the new value of hue each time. Has anyone any idea why the emitter won't update? I'm at

Spritekit Animation Not Changing

一世执手 提交于 2021-01-28 00:02:21
问题 I have a virtual control pad in my game. If I tap and hold on one of the direction buttons, the player moves in the correct direction and shows the proper images and animation. However, if I slide my finger from one control to another one (say right to down), the player moves down but the image and animation don't change until I lift my finger. Below is my code for handling the touches: override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in (touches as! Set

SpriteKit: find all descendants of SKNode of certain class?

房东的猫 提交于 2020-12-08 08:09:55
问题 This question shows how to find all children of a SKNode that belong to a certain class, but what if we want all descendants (e.g., grandchildren) that belong to a certain class? Is there a native way to do this in SpriteKit, or is the only option to create a recursive form of the solution from the aforementioned question? The SKNode documentation highlights a search function that lets you find descendants with a certain name, but is there a way to filter descendants by class and not be name?

SpriteKit: find all descendants of SKNode of certain class?

瘦欲@ 提交于 2020-12-08 08:09:06
问题 This question shows how to find all children of a SKNode that belong to a certain class, but what if we want all descendants (e.g., grandchildren) that belong to a certain class? Is there a native way to do this in SpriteKit, or is the only option to create a recursive form of the solution from the aforementioned question? The SKNode documentation highlights a search function that lets you find descendants with a certain name, but is there a way to filter descendants by class and not be name?

SpriteKit: find all descendants of SKNode of certain class?

懵懂的女人 提交于 2020-12-08 08:06:15
问题 This question shows how to find all children of a SKNode that belong to a certain class, but what if we want all descendants (e.g., grandchildren) that belong to a certain class? Is there a native way to do this in SpriteKit, or is the only option to create a recursive form of the solution from the aforementioned question? The SKNode documentation highlights a search function that lets you find descendants with a certain name, but is there a way to filter descendants by class and not be name?