sprite-kit

How do you get the original filename of a sprite/texture in Swift?

烂漫一生 提交于 2019-12-23 03:10:56
问题 I create a sprite and assign an image file to it. var logoImage = SKSpriteNode(imageNamed: "image1.png") Then in some circumstances, I change the image. logoImage.texture = SKTexture(imageNamed: "image2.png") In another part of the app I want to check which image is currently being displayed. But I don't know how to get the filename. Using: print(logoImage.texture?.description) Returns: "<SKTexture> 'image2.png' (500 x 500)" Which obviously contains the filename, but how do I get the filename

didBeginContact not being called Swift

亡梦爱人 提交于 2019-12-23 03:05:17
问题 I am working on an app that when the central ball colour matches a smaller ball that is flying towards the central ball colour the player scores a point. So for this to work I need the didBeginContact function to call when the "enemy" and the "mainBall" collide. The only thing that is moving is the enemy ball as it flies towards the stationary mainBall I believe I have set the bit masks up correctly but the didBeginContact function is not being called. Can someone please help? Here is my code

iOS app runs on device but not in the simulator

我与影子孤独终老i 提交于 2019-12-23 02:39:18
问题 I have the following problem. I'm working on a Spritekit game at the moment. The game runs completely smooth on a iPhone5. When I want to run the app in the simulator, the compiler tells me: fatal error: malformed or corrupted AST file: 'Unable to load module "/Users/macvideo/Library/Developer/Xcode/DerivedData/ModuleCache/3TAGE798UH20R/Darwin.pcm": module file not found' note: after modifying system headers, please delete the module cache at '/Users/macvideo/Library/Developer/Xcode

Add a property observer on an existing property in an iOS library class

社会主义新天地 提交于 2019-12-23 02:08:15
问题 In my SpriteKit game, I want to add a property observer on the fieldBitMask property for the SKPhysicsBody of my sprites. I want to be informed when the fieldBitMask property changes so that I can take some action. I overrode SKPhysicsBody but when I tried assigning the overridden class to a sprite node like a normal SKPhysicsBody object I got a bunch of errors. I also thought about making an extension for SKPhysicsBody, but Apple documentation says, “Extensions can add new functionality to a

Connect Physicsbodies on TileMap in SpriteKit

给你一囗甜甜゛ 提交于 2019-12-23 01:45:23
问题 I use the following function to append physicsbodies on tiles from a SKTileMapNode: static func addPhysicsBody(to tileMap: SKTileMapNode, and tileInfo: String){ let tileSize = tileMap.tileSize let halfWidth = CGFloat(tileMap.numberOfColumns) / 2 * tileSize.width let halfHeight = CGFloat(tileMap.numberOfRows) / 2 * tileSize.height for row in 0..<tileMap.numberOfColumns{ for column in 0..<tileMap.numberOfRows{ let tileDefinition = tileMap.tileDefinition(atColumn: column, row: row) let

AVPlayer play SKVideoNode video ,I just can not control the playback

房东的猫 提交于 2019-12-23 01:29:13
问题 I am using the SpriteKit to play video,this is my code to create the SKVideoNode from AVPlayer: func CreateVideoViewWithAVPlayer(player:AVPlayer) { video = SKVideoNode(AVPlayer: player) let frameLayer=AVPlayerLayer(player: player) //video?. = CGRectMake(0, 0, 100, 100) video?.size = CGSize(width: 1024, height: 768) println(player.currentItem) video?.anchorPoint = CGPoint(x: 0, y: 0) video?.position = CGPoint(x: 0, y: 0) backgroundColor = SKColor.blackColor() self.addChild(video!) } And I

SpriteKit joint: follow the body

有些话、适合烂在心里 提交于 2019-12-23 01:06:14
问题 I've been asked to simplify this question, so that's what I'm doing. I'm struggling in SpriteKit's physic joints (and possibly physic body properties). I tried every single subclass and many configurations but seams like nothing works or I'm doing something wrong. I'm developing Snake game. User controls head of snake which should move at constant speed ahead and user can turn it clockwise or anticlockwise. All the remaining snake's pieces should follow the head - they should travel exactly

Why won't my SKSpriteNodes appear in the scene?

坚强是说给别人听的谎言 提交于 2019-12-23 01:03:28
问题 I am trying to add a couple of nodes to the scene. When I run the app I just have the default gray background. Neither of the nodes appear in the scene. Here is what I have: class GameScene: SKScene { override func didMoveToView(view: SKView) { /* Setup your scene here */ let jumper = SKSpriteNode(imageNamed:"Jumper") jumper.xScale = 0.25 jumper.yScale = 0.25 jumper.position = CGPointMake(50, 300) self.addChild(jumper) let blob = SKSpriteNode(imageNamed:"Blob") blob.position = CGPointMake(160

Objective c - Animate background colour of SKScene

允我心安 提交于 2019-12-22 23:24:13
问题 How would you go about animating the background colour of an SKScene? I've tried a UIView animate, but not surprisingly it didn't work. Is there an equivalent to do this in Sprite-Kit? I'm looking for something like this, but for Sprite-Kit: [UIView animateWithDuration:0.25 animations:^{ self.backgroundColor = [UIColor redColor]; }]; At the moment, as a work around I have overlayed a UIView over the SKView, but I would like something more flexible. I am relatively new to Sprite-Kit, so

ARKit billboarding effect with SceneKit

可紊 提交于 2019-12-22 18:43:21
问题 I am looking to add a billboarding effect that is similar to this application: https://twitter.com/marpi_/status/897130955105644544 I would like SCNodes that use SCNText geometry to always face the camera. I have attempted with out success: SCNLookAtConstraint with sceneView.pointOfView as the target, but this rotates the node to face away from the camera, resulting in backwards text, and unable to change the nodes position or euler angle. Out of the box, an SKLabelNode will always face the