skspritenode

Troubles using CGPathContainsPoint SWIFT

吃可爱长大的小学妹 提交于 2019-12-10 02:02:10
问题 I need to check if a CGPoint is inside a SKSpriteNode. After a little research, CGPathContainsPoint seems appropriated for my purpose. if CGPathContainsPoint(my_sprite_path, nil, my_point, false) { } But Xcode alerts me: Use of unresolved identifier CGPathContainsPoint I tried to import : import UIKit import CoreGraphics I'm using Xcode 8.0 beta 6. Did I miss anything? 回答1: As of Swift 3, many Core Graphics functions are now methods on the corresponding type. In your example: if my_sprite

iOS SpriteKit how to create a node with an image from a folder within app bundle?

自古美人都是妖i 提交于 2019-12-08 21:23:38
问题 I'm trying to create a sprite of a random monster where my images are stored in a folder referenced within the main bundle. NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; NSString* resourceFolderPath = [NSString stringWithFormat:@"%@/monsters", bundlePath]; NSArray* resourceFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourceFolderPath error:nil]; NSInteger randomFileIndex = arc4random() % [resourceFiles count]; NSString* randomFile = [resourceFiles

how to add SKSpriteNode in a loop [closed]

被刻印的时光 ゝ 提交于 2019-12-08 11:37:43
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I want to add some squares in a scene by loop. But this code has a problem. What is wrong? var shape = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 100, height: 100)) for (var i=0 ; i<10 ; i++) { shape.name = "shape\(i)" shape.position = CGPointMake(20,20) self.addChild(shape) } 回答1: You have a

Texture for sprite not found and sprite not displayed when using SKSpriteNode with a category

旧城冷巷雨未停 提交于 2019-12-08 11:26:10
问题 I started using SKSpriteNode category system for extending the base functionality of the SKSpriteNode, and the sprites added to the .sks scene through the editor are now missing from the scene (not the ones programmatically added to the scene additionaly, in runtime). When I logged some of the sprites on the .sks, I can see their correct location, and scale parameters, but texture is always ['nil'] in the debugging console in XCode. This happens (see below NSLog line) when I for instance log

Collision detection leading to color detection? [duplicate]

和自甴很熟 提交于 2019-12-08 09:34:32
问题 This question already exists : Do an SKAction if the colors of two sprites aren't the same? [duplicate] Closed 3 years ago . How can I check if, when I collide with an SKSpriteNode in the middle of two rectangles with a ball, the ball and the two rectangles are the same color? For example, if my two rectangles are red, and my ball is blue, I want it to detect that the colors of my rectangle and the ball are different. If they are the same color, then I don't want anything to happen. If they

Touch Sprite, make it jump up then fall down again(repeat as many times as spritenode is tapped.)

北战南征 提交于 2019-12-08 03:15:04
问题 I created a project where I have a ball and when the view loads, it falls down, which is good. I'm trying to get the ball to jump back up and fall down again when the Spritenode is tapped. --This Question was edited-- Originally, I was able to get it to work when sprite.userInteractionEnabled = false . I had to turn this statement true in order to get the score to change. Now I can't get the balls to fall and be tapped to jump. When I turn ball.physicsBody?.dynamic = true , the balls will

How do I convert a PNG with alpha to RGBA4444 for using it in SpriteKit SKTexture?

家住魔仙堡 提交于 2019-12-08 00:04:24
问题 I have a stack of transparent PNGs that I'd like to use in a SKSpriteNode animation with SKTexture s. I'd need to adjust the memory usage of SKTexture s by reducing texture quality down from RGBA8888 to RGBA4444 . How would I initialize SKTexture with RGBA4444 texture format? Edit: IOS Swift Game Development Cookbook: Simple Solutions for Game Development suggests that SKTexture would support PVRTC files as follows: However, I couldn't get a SKSpriteNode to display a texture generated this

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

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