sprite-kit

iOS spriteKit child nodes position with respect to view coordinates

霸气de小男生 提交于 2019-12-23 08:05:05
问题 I have a child node added to another node. I want to get the child nodes position with respect to the views coordinates and not the parent nodes coordinates 回答1: Get the child node's position with respect to its parent, then use the convertPoint:fromNode: or convertPoint:toNode: method to convert from the parent node's coordinate system to the scene's coordinate system. (Remember, SKScene inherits from SKNode and is the root of the node hierarchy, so you can use it with either of those

Can I add a border to an SKSpriteNode, similar to UIView?

泄露秘密 提交于 2019-12-23 07:42:13
问题 I'm interested if an SKSpriteNode can be made to imitate the behavior of a UIView where I can specify border and corner radius? self.view.layer.borderColor = [UIColor lightGrayColor].CGColor; self.view.layer.borderWidth = 2; self.view.layer.cornerRadius = 2; self.view.layer.masksToBounds = YES; 回答1: Not natively. Though you can just add a SKShapeNode as child whose path you create with CGPathCreateWithRoundedRect . 回答2: The following is a simple, dropin extension for SKSpriteNode that will

SKVideoNode only on a small part of SCNSphere

给你一囗甜甜゛ 提交于 2019-12-23 07:23:09
问题 I'm using SKVideoNode as a material for my sphere for 360 video, but it only renders the video on the xy positive part of the sphere, I'm streaming the video from a URL it's a .m3u8 for reference see - SKVideoNode as texture for SCNSphere Multiple people seem to be having the same issue as me func makeSphere() { let sceneView = SCNView(frame: self.view.frame); self.view.addSubview(sceneView); var screenSize: CGRect = UIScreen.mainScreen().bounds; var screenWidth = screenSize.width; var

Does a parent have its children's physicsBodies?

隐身守侯 提交于 2019-12-23 06:20:48
问题 I was wondering what the physicsBody of a parent would be if all I do is this: let combinedBodies = SKSpriteNode() addChild(combinedBodies) //Create its children like this as an example: let child = SKSpriteNode(color: UIColor.red, size: CGSize(width: 10, height: 20)) child.physicsBody = SKPhysicsBody(rectangleOf: child.size) child.physicsBody?.categoryBitMask = collisionType.child.rawValue combinedBodies.addChild(child) allBodies.append(child.physicsBody?) Would the physicsBody of

Detecting touches in a triangular grid of buttons?

不想你离开。 提交于 2019-12-23 04:32:12
问题 In the photo below, each triangle is a separate subclassed SKShapeNode. How do you recognize which triangle is touched? Currently in the scene's toucheBegan: method, touching the grid detects two triangles since their frame's are square. 回答1: I managed to solve this problem by setting the UIBezierPath path that draws the triangle as a property on the Triangle class. In the scene's toucheBegan: method, I check if the touch is contained within the Triangle's touchableArea UIBezierPath property.

Interstitial ad with admob at gameOverScene

不问归期 提交于 2019-12-23 04:29:47
问题 I have searched the internet high and low for direction regarding adding an interstitial admob ad at the game over scene with SpriteKit when using swift. The google documentation still uses Obj-C. What I have gathered so far is that I need to initialize the ad in the viewController and then call it from the game over scene? Any advice would be greatly appreciated. 回答1: Updated solution I set in the view controller in the viewdidload NSNotificationCenter.defaultCenter().addObserver(self,

Interstitial ad with admob at gameOverScene

為{幸葍}努か 提交于 2019-12-23 04:29:10
问题 I have searched the internet high and low for direction regarding adding an interstitial admob ad at the game over scene with SpriteKit when using swift. The google documentation still uses Obj-C. What I have gathered so far is that I need to initialize the ad in the viewController and then call it from the game over scene? Any advice would be greatly appreciated. 回答1: Updated solution I set in the view controller in the viewdidload NSNotificationCenter.defaultCenter().addObserver(self,

SKAction: how to generate a random delay in generation of nodes

夙愿已清 提交于 2019-12-23 04:02:31
问题 I use the following piece of code to generate SKNodes periodically. Is there a way to make the period of generation of these SKNodes random. Specifically, how do I make the "delayFish" in the following code an action with a random delay? [self removeActionForKey:@"fishSpawn"]; SKAction* spawnFish = [SKAction performSelector:@selector(spawnLittleFishes) onTarget:self]; SKAction* delayFish = [SKAction waitForDuration:3.0/_moving.speed]; SKAction* spawnThenDelayFish = [SKAction sequence:@

SpriteKit SKTextureAtlas, Terminated Due to Memory Pressure while loading texture

本秂侑毒 提交于 2019-12-23 03:33:12
问题 Similar to the SpriteKit Featured Game "Adventure" from WWDC, I am try to load my background image via tiles. I have created a Texture Atlas that contains 6,300 "tiles" that are each 100x100 pixels in size. The complete background image is a total of 30,000x2048 (for retina displays). The idea is that the background will move from right to left (side-scroller). The first column and the last column match so that they seem continuous. When the application runs, it loads my initial loading

How can I create a 'share to Facebook button' in a SpriteKit game using swift?

£可爱£侵袭症+ 提交于 2019-12-23 03:22:27
问题 I have made a simple game using the Game template in Xcode, coded in swift. I created a shapeNode, and when it is touched, I would like this code to run: if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){ var controller = SLComposeViewController(forServiceType: SLServiceTypeFacebook) controller.setInitialText("Testing Posting to Facebook") //self.presentViewController(controller, animated:true, completion:nil) } This code is run in the GameViewController.swift file,