sprite-kit

Choosing random image for SKSpriteNode

坚强是说给别人听的谎言 提交于 2019-12-07 21:49:03
问题 I am trying to build a simple obstacle jumping app. I want the image for the obstacle to be picked randomly from a set of images. I have tried using a combination of the arc4random_uniform function and switch case but that doesn't seem to update the SKSpriteNode. What am i doing wrong? class PlayScene: SKScene, SKPhysicsContactDelegate{ ... var block3 = SKSpriteNode(imageNamed: "lion") .... } override func update(currentTime: NSTimeInterval) { ..... blockRunner() } func blockRunner() { var

Present an UIAlertController with a SpriteKit scene (Objective-C)

淺唱寂寞╮ 提交于 2019-12-07 20:51:56
问题 I'm trying to make a SpriteKit app that has a button to go to my website if the user so desires to. I thought it would be a good practice to make an alert (since it's made for iOS 8, I'd use a UIAlertController ) confirming if they want to be redirected to Safari to see it. Here's what I have in code for the method to make/present this alert so far: UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Go to website" message:@"Would you like to visit DannyDalton

.png animation slow performance in spritekit

萝らか妹 提交于 2019-12-07 20:18:25
问题 i have a .png animation in my project with 700 pics and a size of 150 px x 150 px. it works fine but everytime, the animation starts, the whole game freezes for about 0.1 sec. like its loading but i implemented the .png array in initWithSize. like this: SKTextureAtlas *barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"]; NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNames]; NSArray *sortetBarrierUfoAtlasNames = [barrierUfoAtlasNames sortedArrayUsingSelector:

does swift not allow initialization in function parameters?

白昼怎懂夜的黑 提交于 2019-12-07 19:49:39
问题 This first block generates a generic Swift Compile Error (doesn't even point to the line) let screenDivision = size.width / 5; var game1 = SKSpriteNode(color: .redColor(), size: CGSize(width: 2 * screenDivision, height: size.height)); This second block works fine. let screenDivision = size.width / 5; var a = CGSize(width: 2 * screenDivision, height: size.height) var game1 = SKSpriteNode(color: .redColor(), size: a); Why? I'd hate to run into this error again and not remember where I wrote

Assigning an image to a SKShapeNode as a Ball - Spritekit Game

让人想犯罪 __ 提交于 2019-12-07 19:37:43
问题 I am trying to add an image to my ball in my Swift 2 Sprite-kit game. I have a make() ball function and it there are no errors there however in the game scene, when the method is called, I keep receiving this error : "Cannot assign SKShapeNode' to type Ball! I am not sure how to fix and am new to Swift. // ----- GameScene.Swift ---- class GameScene: SKScene, GameDelegate, SKPhysicsContactDelegate { // ball part one var ball: Ball! let ballSpeedX = CGFloat(500) } override func didMoveToView

iCarousel in Sprite Kit

你说的曾经没有我的故事 提交于 2019-12-07 19:37:34
问题 Explanation I'm trying to build a character selection menu similar to Crossy Road's one (as you can see here). So I found this iCarousel, which would help me with all of it, but everything I read talk about implementing it to a ViewController , which isn't my case. I'm using GameScene and I didn't found anything talking about it. Is there anyway I could implement it to my game? or even another effect similar to the character selection menu I mentioned above? Attempt (beyowulf) You can

how do I cut a hole in a sprite image or texture to show what is behind it using spriteKit in swift

南笙酒味 提交于 2019-12-07 19:30:19
问题 I would like to display a bunch of draggable images in spriteKit. Some of the images will require me to cut a hole in the graphic dynamically so I can see what is behind the images. And as I drag around the images I'll be able to see the other images through the holes I've cut in the images. If you need a visual, think of jigsaw puzzle pieces. This stack exchange link below looked very simple and promising, but the white circle cutout doesn't seem to display. At least not in the simulator. I

creating buttons in skview to point to different scenes

笑着哭i 提交于 2019-12-07 19:18:26
i am trying the sprite kit for the first time. just to state the obvious, I've been through the doc's but i can't quiet grasp the idea of creating multiple buttons yet. i can create the buttons alright. and they appear in my view, but i can't attach the function to them in order to point to different views. here is the code I'm using for creating the buttons and so on: #import "Levels.h" #import "MyScene.h" #import "MyScene1.h" @interface Levels () @property BOOL contentCreated; @end @implementation Levels - (void)didMoveToView: (SKView *) view { if (!self.contentCreated) { [self

SKSpriteNode can't load image from Images.xcassets in some iOS 9 simulators

倖福魔咒の 提交于 2019-12-07 19:10:34
问题 I was working on a game using SpriteKit recently and found an interesting problem. When I initiated a SKSpriteNode from an image saved in the Images.xcassets, it didn't work in some iOS 9 simulator. The code I used is: let tortoise = `SKSpriteNode`(imageNamed: "tortoise") When testing it in simulators, I found although it worked in most iOS 8.4 and iOS 9 simulators, it didn't work in iPad 2 (iOS 9) and iPhone 4s (iOS 9). The SKSpriteNode wasn't displayed in those 2 simulators and the

Unwrapping optional values: PhysicsBody - Swift SpriteKit

不想你离开。 提交于 2019-12-07 18:21:32
问题 So I made some adjustments to the ball in my game and to avoid an unwrapping optional value error, I commmented out the following //didMoveToView self.physicsWorld.gravity = CGVectorMake(0, 0) self.physicsWorld.contactDelegate = self let fieldBody = SKPhysicsBody.init(edgeLoopFromRect: self.frame) self.physicsBody = fieldBody self.physicsBody!.affectedByGravity = false self.physicsBody!.usesPreciseCollisionDetection = true self.physicsBody!.dynamic = true self.physicsBody!.mass = 0 self