sprite-kit

SKPhysicsJointFixed doesn't keep nodes together while moving one

*爱你&永不变心* 提交于 2019-12-12 18:09:16
问题 I've created 2 SKSpriteNodes, and connected them by a SKPhysicsJointFixed, to keep them stuck together. The problem is when I apply a SKAction.move(by:, duration:) to the first, it moves alone. why is that, and how can I move them together? I've searched a lot, but can't seem to find any new or useful information. Please help. Thanks in advance. Here's the code: import SpriteKit class myGame: SKScene { var node1: SKSpriteNode! var node2: SKSpriteNode! func createNode(_ position: CGPoint,

Random value in Swift

偶尔善良 提交于 2019-12-12 17:30:19
问题 I'm trying to have a value who is between 0 and the size of my screen. So i did it like this : let sizeX = Int(CGRectGetMaxX(self.frame)) let sizeY = Int(CGRectGetMaxY(self.frame)) var randomX = CGFloat(arc4random()) % sizeX var randomY = CGFloat(arc4random()) % sizeY self.touchButton.position = CGPointMake(randomX, randomY) I have this error : could not find an overload for '%' that accepts the supplied arguments I need this to randomize the position of an SkSpriteNode, maybe is there a

In SpriteKit presentScene Transition, won't work. However, presentScene does

白昼怎懂夜的黑 提交于 2019-12-12 16:44:07
问题 let reveal = SKTransition.doorwayWithDuration(0.5) reveal.pausesIncomingScene = false reveal.pausesOutgoingScene = true //self.skView!.presentScene(self.gameOverMenu!, transition: reveal) self.skView!.presentScene(self.gameOverMenu) That is the portion of code I'm using to present the new scene. The skView already has a scene running, I'm doing this from the view controller. When I do present scene it all works fine. But when I try to add the transition the new scene never shows up. The

SKPhysicsBody not as expected

杀马特。学长 韩版系。学妹 提交于 2019-12-12 14:18:00
问题 I have the following code to create a rectangular brick and a physics body associated with it. I expected the physics body to be a solid rectangle same size and position as that of the brick, but am getting a body which I think has a poition offset and perhaps also a size difference. Is there some issue with the coordinate systems I have missed? What is the right way to approach this? - (void)addBrick { SKShapeNode *brick = [[SKShapeNode alloc] init]; CGRect brickBoundary = CGRectMake(0.0, 0

SpriteKit PhysicsBody non-rectangular collision

╄→尐↘猪︶ㄣ 提交于 2019-12-12 13:15:49
问题 pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size) in this coding I used the rectangleOfSize for collision physics body, but if I want to use by pixel just the shape of the image, what I should use instead of rectangleOfSize ? 回答1: You should make a CGPath that is the shape of your object, and use SKPhysicsBody 's init(polygonFromPath path: CGPath) as described here 回答2: I'd use KnightOfDragon's method with the addition of the size : parameter like this: pipeUp.physicsBody =

Swift, spritekit: In app purchase code runs, NOTHING happens?

微笑、不失礼 提交于 2019-12-12 12:49:29
问题 Ok, so I'm working in Swift and I just need help. I have followed 4 different tutorials on how to implement in app purchases in sprite kit with Swift, copied code verbatim, and nothing is working for me. Here are the steps I have taken: Gone in Itunes Connect and created an in app purchase under my app's record. My in app purchase's product Id is "GameOverSaveSavior" In Xcode, I've turned my app's In app purchase capability to ON , made sure my team is set to my account, and made sure my

Position of mouse click relative to scene, not window

有些话、适合烂在心里 提交于 2019-12-12 12:48:07
问题 In my game I need to use the mouse to select units. However, I am encountering problems as I do not know how to get the coordinates of the click relative to the game, not to the window. For example, if Unit 1 is at the (0,0) point of the game, it could be at any point on the window depending on how I pan and zoom the window, but I want the mouse click to return (0,0) no matter how I move the window as long as I click on the same spot. Right now I am using: override func mouseDown(with event:

How can I enable iAd when using Sprite Kit?

一世执手 提交于 2019-12-12 12:41:34
问题 In IOS 7, we can enable iAd very easy when using: self.canDisplayBannerAds = YES; in code ViewDidLoad of UIViewController However, I cannot use this in my ViewController (the ViewControl that load SKScene). My game is crash when loading. So how can I active iAd in my game (using Sprite Kit)? 回答1: You can only show iAd in a UIViewController subclass. You are doing it right. Put the following code in your UIViewController and not in the SKScene. Please refer to this tutorial for the exact code:

Unable to create array of SKActions

那年仲夏 提交于 2019-12-12 12:12:15
问题 I'm experimenting with SpriteKit in Swift but somehow seem unable to create an array of actions to use in a sequence. I've split it up to try and pin-point the problem, but no luck so far. func animateBackground(){ let moveLeft = SKAction.moveByX(100, y: 0, duration: 3) moveLeft.timingMode = SKActionTimingMode.EaseInEaseOut let moveRight = SKAction.reversedAction(moveLeft) let actions = [moveLeft, moveRight] // <--- here there be dragons/trouble let sequence = SKAction.sequence(actions) let

Convert UIKit coordinates to SpriteKit coordinates

风格不统一 提交于 2019-12-12 10:47:12
问题 I am trying to convert normal uikit coordinates (top left origin, width and height go right and down) to Sprite Kit coordinates (origin is at center of node, left and down are negative, right and up are positive). Does anyone know how to do this? Unfortunately I can't work around this to my knowledge because I am using QuartzCore for drawing on a SKNode. Without converting, I am getting really off drawings. 回答1: According to the docs, SKView has methods for Converting Between View and Scene