sprite-kit

How to use a sprite sheet in swift and sprite kit?

佐手、 提交于 2019-12-09 06:35:13
问题 Title says it all. How do i use a sprite sheet in swift and sprite kit? I've searched google, stack exchange, and the apple documentation and I can't figure this one out. 回答1: In xcode 7, you can use Images.xcassets to create a sprite atlas. Click on Images.xcassets Click on the plus bottom in the bottom left Select "new sprite atlas" Then you can drag and drop all your images into the atlas If you drag in all three image sizes with the proper suffix (@2x and @3x) it will automatically

Swift Spritekit isometric map touch location

僤鯓⒐⒋嵵緔 提交于 2019-12-09 06:07:50
问题 I've started doing a small swift / spritekit project to teach myself game dev. It starts with an isometric map, which I managed to draw. But I'm having trouble getting a precise touch location on the different tiles of the map. It works, but is slightly out of place, and does not seem consistent. Here are my functions : class PlayScene: SKScene { let map = SKNode() override func didMoveToView(view: SKView) { let origin = view.frame.origin let mapOrigin = CGPointMake(origin.x + self.frame

SKVideoNode (embedded in SKScene) as texture for for Scene Kit Node not working

戏子无情 提交于 2019-12-09 05:52:59
问题 I'm attempting to map a video as texture to a primitive cylinder for a VR project by using Scenekit: an SKVideoNode embedded in an SKScene as a texture for a SceneKit SCNTube object, and I just can't get video to display as a still image would. PLayground code below should generate moving video mapped to cylinder, but the mapping does not work: EDIT: ADDED SINGLE LINE AT END OF LISTING TO FIX. CODE BELOW SHOULD WORK import UIKit import SceneKit // for 3D mapping import SpriteKit // for

Difference between paused property of SKScene and SKView

ぃ、小莉子 提交于 2019-12-09 05:23:01
问题 I am pausing my SKScene using the following code: self.paused = YES; However, according to this answer by Andrey Gordeev, one can also pause a scene using this line: self.view.paused = YES; I would like to understand what difference it would make to call the either (or both) to pause a scene. 回答1: Pausing SKView stops calling update: method for SKScene . Pausing SKScene doesn't do that. I usually pause both SKScene and SKView EDIT: As of iOS9 pausing the scene will pause the update: method.

Is there a way to visually see sprite kit's SKPhysicsbody borderline?

假装没事ソ 提交于 2019-12-09 05:04:27
问题 I am using bodyWithPolygonFromPath to define the volume of the physicsbody, and used http://dazchong.com/spritekit/ to get the paths required. But the path does not seem correct and I wish to see the borderline of the physicsbody path to see if the shape is correct. Is there any way to see the physicsbody's volume outline? I tried the following code, but it doesn't work. ship = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"]; CGFloat offsetX = ship.frame.size.width * ship.anchorPoint.x;

dealing with different screen sizes in xcode

给你一囗甜甜゛ 提交于 2019-12-09 04:52:26
I have an iPhone game that was first developed for iPhone 6 and when played on the iPhone 5 sim it works fine but when played on the iPhone 4 sim the sides are stretched out?!? and the nodes that I spawn in from the left and the right side spawn on the screen instead of off the screen like on the iPhone 6 and 5. (please don't say this is a duplicate as I have been looking for weeks of how to deal with different iPhones) I have arrows coming in the from the left and the right that spawn randomly on the y axis. They spawn off screen then slowly move on screen than move quickly across the screen

How do you change the color of all of the nodes of a specific name in SpriteKit with Swift

耗尽温柔 提交于 2019-12-09 04:11:35
I'm trying to change the color of every single instance of a node in SpriteKit. When I try to put it in the update method, it only changes one and not all of them. override func update(currentTime: CFTimeInterval) { if changeColor { self.enumerateChildNodesWithName("blocks", usingBlock: { node, stop in block?.color = UIColor.orangeColor() }) } } I think you should change the color of the node , not of some block variable. You will retrieve all SKNode s with that name. But those nodes don't have a color property. Only some subclasses, for example the SKSpriteNode have a color property. You

SKEffectNode to an SKTexture?

南笙酒味 提交于 2019-12-09 03:38:55
问题 SKEffectionNodes have a shouldRasterise "switch" that bakes them into a bitmap, and doesn't update them until such time as the underlying nodes that are impacted by the effect are changed. However I can't find a way to create an SKTexture from this rasterised "image". Is it possible to get a SKTexture from a SKEffectNode ? 回答1: I think you could try a code like this (it's just an example): if let effect = SKEffectNode.init(fileNamed: "myeffect") { effect.shouldRasterize = true self.addChild

360 degrees spinnable object from a photographed real object

删除回忆录丶 提交于 2019-12-09 02:14:15
问题 I want to create the ability to spin a photographed object 360 degrees. It spins endlessly based on the speed you "flick" . You spin it left or right by flicking the object left or right . You stop the spin when you touch to stop it if it's spinning. Similar to the app The Elements by Theodore Grey. Here's a video of the part of the app I'm trying to recreate. (i.e. the 3D spinner) https://youtu.be/6T0hE0jGiYY Here's a video of my finger interacting with it. https://youtu.be/qjzeewpVN9o I'm

How do I control playback of a video in an iOS Sprite Kit SKVideoNode?

那年仲夏 提交于 2019-12-09 02:04:39
问题 I load a video into my Sprite Kit SKVideoNode, but how do I stop and restart the playback or go to a specific time in the video? All I see are play and pause methods. // AVPlayer NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HowToPlay" ofType:@"mp4"]]; _avPlayer = [AVPlayer playerWithURL:fileURL]; // SKVideoNode _videoNode = [SKVideoNode videoNodeWithAVPlayer:_avPlayer]; [_videoNode play]; 回答1: This turned out to work for me. Restart: [_videoNode