sprite-kit

Swift - Adding background image behind a Sprite Kit Scene in View Controller

荒凉一梦 提交于 2019-12-12 01:19:30
问题 I am trying to add a background image in my view controller so my sprite kit game scenes can be in the foreground. It's important for me for my background image to stay on screen while the game scenes transition to each other. The problem I am having is how to place the subview I created for my background to be behind my skscene, at the moment my background image is in front of my game scene and all you can see is the image sendSubviewToBack doesn't seem to work. The following is my

SKTexture from UIImage looks different

橙三吉。 提交于 2019-12-12 01:13:18
问题 I'm playing around with SpriteKit and I'm creating a SKTexture from an UIImage, then using SKSpriteNode to add the child to my SKScene (As a background), everything works fine, except that the UIImage looks very different from the original image, I tried to recreate the image in photoshop and the issue still remains, tested on Simulator and real device and different image colors, no changes. The image format is PNG, and I added through Images.xcassets in Xcode 5 Image, results: Different

Ellipse SKPhysicsBody

跟風遠走 提交于 2019-12-12 01:07:13
问题 Which SKPhysicsBody body type would I use to create an elliptical physicsBody? I know I could make a curve out of straight lines and just have it not be a real ellipse, but it seems like there must be some way to squish a circle or create one? 回答1: Create an elliptical CGPath and create a polygon body with that path: CGPathRef path = CGPathRef CGPathCreateWithEllipseInRect(someRect, nil); SKPhysicsBody* body = [SKPhysicsBody bodyWithPolygonFromPath:path]; It's possible though that the created

“Attemped to add a SKNode which already has a parent” error when trying to spawn a node

南楼画角 提交于 2019-12-12 00:36:00
问题 The error that I keep getting is this one: Attemped to add a SKNode which already has a parent . I have tried to take out the spawn function and it works without it. Can someone please help me ? func spawnTrolls(){ let minValue = self.size.width / 10 let maxValue = self.size.width - 30 let spawnpoint = UInt32(maxValue - minValue) Troll.position = CGPointMake(CGFloat(arc4random_uniform(spawnpoint)), self.size.height) self.addChild(Troll) let action = SKAction.moveToY(-70, duration: 2) let

skshapenode adding two nodes?

霸气de小男生 提交于 2019-12-12 00:25:24
问题 I'm not sure whether there's an issue with the implementation or the way I'm using it. However, it's presenting over 2,400 nodes when it should be ~ 1,250 -(void)drawWeb { //get distance of 50 across int distanceMargin = _background.frame.size.width/50; NSLog(@"%i", distanceMargin); __block int xCounter = distanceMargin; __block int yCounter = 0; NSArray *alphabet = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",

Object positioning is off

╄→尐↘猪︶ㄣ 提交于 2019-12-11 23:36:45
问题 Hi, I’m trying to get an object (in this case a green frog) to spawn in line with the player sprite (the red frog) on a platform which is as wide as the scene and what i mean by this, is getting the object to spawn so that when the player advances it doesn’t overlap the object. (The picture shows how the green frog is between two red frogs and not in line with one of the red frogs) My code for positioning of the objects is as follows obstacle.position = CGPointMake(-(backgroundSprite.size

removeFromParent() Doesn't Work in SpriteKit

被刻印的时光 ゝ 提交于 2019-12-11 23:16:23
问题 I have a loop in my SpriteKit game that randomly produces duplicates of an object and I'd like to use removeFromParent() to remove my object on contact. However, when I add it to the code, the object isn't removed. Here is my code for the loop that generates my object: for i = 0; i<1000; ++i { var randomNumber = CGFloat(arc4random_uniform(3000)) * 200 bubbleDuplicate.position = (CGPointMake(randomNumber, 400)) bubbleDuplicate = bubble.copy() as! SKSpriteNode bubbleDuplicate.physicsBody?

SpriteKit crashing with std::out_of_range: vector issue

こ雲淡風輕ζ 提交于 2019-12-11 23:14:28
问题 So I am trying to pin down exactly what is the cause of this crash. Please see the crash report here: This is what is produced in the log: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector Basically the crash does not happen all the time and seems to happen on more recent iOS devices. If I clean my build I have noticed that the chances of it happening are much less likely. I am assuming it has something to do with maybe my textures atlases? Has anyone had

UIView won't cast to SKView

梦想的初衷 提交于 2019-12-11 22:52:16
问题 I've been trying to implement Game Center in my Sprite Kit game, but every time I try to present the leaderboard... -(void)showLeaderboard:(UIViewController*)gcvc { GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init]; if (leaderboardController != NULL) { leaderboardController.leaderboardIdentifier = @"Game_Leaderboard"; leaderboardController.viewState = GKGameCenterViewControllerStateLeaderboards; leaderboardController.gameCenterDelegate = self;

Removing Background of SKView - Particle Emitter - SpriteKit

流过昼夜 提交于 2019-12-11 22:44:12
问题 So I followed this tutorial and created a small particle emitter for when the player achieves a goal (kinda like a celebration). I'm using a single view application, just like the tutorial, but I can't seem to remove the background of the emitter... so I get a black square underneath the particles. I changed the View / SKView in storyboard to clear colour, but it still appears to be black when the app is run... Apple Docs say this: To create an emitter with no background color, set the