sprite-kit

How to rotate sprites around a joint

耗尽温柔 提交于 2020-02-11 14:04:51
问题 I need to make the arms and hands rotate around the center of the hook, as shown in the image below without them separating or changing their shape (no changes in the angles between arms and hands just rotation at A), as in the image below: I tried rotating the arms but this made them separate and change form. You can check out my code below: let hookCategoryName = "hook" let leftArmCategoryName = "leftArm" let rightArmCategoryName = "rightArm" let leftHandCategoryName = "leftHand" let

How to rotate sprites around a joint

若如初见. 提交于 2020-02-11 14:02:29
问题 I need to make the arms and hands rotate around the center of the hook, as shown in the image below without them separating or changing their shape (no changes in the angles between arms and hands just rotation at A), as in the image below: I tried rotating the arms but this made them separate and change form. You can check out my code below: let hookCategoryName = "hook" let leftArmCategoryName = "leftArm" let rightArmCategoryName = "rightArm" let leftHandCategoryName = "leftHand" let

How to simulate Gravity in z-axis in a 2D game with Sprite Kit

我与影子孤独终老i 提交于 2020-02-07 07:26:34
问题 I'm writing a 2D ball game with sprite kit on iOS 7 and currently struggling on one physic simulation. To explain the expected behavior: if a ball is dropped into a tea cup, it will circle around, loosing speed and finally stand still in the center of the cup. I've tried to archive this with gravity, but gravity in sprite kit only applies to vertical X and Y axis, not Z-axis. I also tried to use level gravity by switching gravity values with small physic bodies on beginContact depending on

How to set contactDelegate for physicsWorld in SpriteKit?

我的梦境 提交于 2020-02-06 23:32:11
问题 I have just encountered a problem when assigning contactDelegate to self (GameScene). override func didMoveToView(view: SKView) { self.physicsWorld.contactDelegate = self /* ... */ } Unfortunately, I get an error: Cannot assign a value of type 'GameScene' to value of type 'SKPhysicsContactDelegate?' This wouldn't happen in previous versions of Xcode (probably something new in Swift 2.0), so even in SpriteKit documentation on Apple Developer they have the same code I do. How do I get around

How to set contactDelegate for physicsWorld in SpriteKit?

折月煮酒 提交于 2020-02-06 23:24:09
问题 I have just encountered a problem when assigning contactDelegate to self (GameScene). override func didMoveToView(view: SKView) { self.physicsWorld.contactDelegate = self /* ... */ } Unfortunately, I get an error: Cannot assign a value of type 'GameScene' to value of type 'SKPhysicsContactDelegate?' This wouldn't happen in previous versions of Xcode (probably something new in Swift 2.0), so even in SpriteKit documentation on Apple Developer they have the same code I do. How do I get around

How do you use the Delegate Protocol Pattern with SpriteKit?

删除回忆录丶 提交于 2020-02-06 07:59:28
问题 So I have one UIViewController and two SKScene s. The UIViewController present the two scenes by rotating the device; landscape load SKScene 1 and portrait load SKScene 2 lie this: override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { print("TRIGGERED") if UIDevice.current.orientation.isLandscape { print("Landscape") presentView(name: "GameScene") } else { print("Portrait") presentView(name: "GameScene2") } super.viewWillTransition(to:

How do you use the Delegate Protocol Pattern with SpriteKit?

两盒软妹~` 提交于 2020-02-06 07:59:05
问题 So I have one UIViewController and two SKScene s. The UIViewController present the two scenes by rotating the device; landscape load SKScene 1 and portrait load SKScene 2 lie this: override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { print("TRIGGERED") if UIDevice.current.orientation.isLandscape { print("Landscape") presentView(name: "GameScene") } else { print("Portrait") presentView(name: "GameScene2") } super.viewWillTransition(to:

SpriteKit physics false positive?

徘徊边缘 提交于 2020-02-06 05:50:47
问题 The contact point provided by didBeginContact does not always rest in the paths that define the physics bodies involved in the collision. This behavior is most problematic in cases where the bodies never come into contact (if the circle node is 1px further right, the contact still happens though it is mathematically impossible.) In the image and program below, the rectangle has a width of 100px, but the contact point (shown in the output) is at 101.4550... import SpriteKit class GameScene:

SpriteKit SKScene add AVCaptureVideoPreviewLayer CALayer as background not working

柔情痞子 提交于 2020-02-04 05:24:33
问题 I'm attempting to add the AVCaptureVideoPreviewLayer CALayer as the background to my SKScene. I can add the CALayer to the scene, but no matter what attempts at ordering the CALayer is always the top most object. In the didMoveToView I have the function: - (void) didMoveToView:(SKView *)view { [self addVideo]; } Which calls the addVideo function: -(void) addVideo { AVCaptureSession *captureSession = [[AVCaptureSession alloc] init]; captureSession.sessionPreset = AVCaptureSessionPresetHigh;

Make SKSpriteNode flash white with SKAction colorizeWithColor

北城余情 提交于 2020-02-03 08:14:52
问题 Ok so I have a sprite thats suppose to flash white when hit by something, I'm using this SKAction *changeColorAction = [SKAction colorizeWithColor:[SKColor whiteColor] colorBlendFactor:1.0 duration:1]; What happens is the sprite flashes, but instead of white, it just turns transparent. If I use any other color like redColor, blueColor, ect.. It works perfect. How can I get it to actually turn white? Thanx for the help!!! :D 回答1: Colorize with white should give you the image's original colors.