sprite-kit

How to make SKSpriteNode reappear on the opposite side of its SKScene?

♀尐吖头ヾ 提交于 2019-12-09 22:36:56
问题 I have been experimenting with SpriteKit for some time now, and I would appreciate some “best practice” input regarding the movement of my SKSpriteNode within its SKScene’s bounds. Using the accelerometer, I am applying forces on an SKSpriteNode's PhysicsBody property in order to move the node around the screen in a marble-like fashion. Currently, I set the PhysicsBody of my scene using self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame] so that the marble simply bounces

SpriteKit conveyor belt

喜欢而已 提交于 2019-12-09 21:00:08
问题 I am trying to create a conveyor belt effect using SpriteKit like so MY first reflex would be to create a conveyor belt image bigger than the screen and then move it repeatedly forever with actions. But this does not seem ok because it is dependent on the screen size. Is there any better way to do this ? Also obviously I want to put things (which would move independently) on the conveyor belt so the node is an SKNode with a the child sprite node that is moving. Update : I would like the

Spinning a prize wheel with touchesMoved in SpriteKit

拜拜、爱过 提交于 2019-12-09 18:36:27
问题 is it possible to use applyAngularImpulse but not exponentially increase the speed of the wheel? Ideally I'd like to have the wheel follow my finger, but setting node.zRotation += atan2f(y2-y1, x2-x1) spins my wheel out of control. here's what i settled on, but it feels pretty wonky: - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; SKNode *node = [self nodeAtPoint:location]; CGPoint positionInScene = [touch locationInNode:self]; CGPoint

Using SpriteKit inside SwiftUI

你说的曾经没有我的故事 提交于 2019-12-09 17:58:58
问题 I am having an issue when creating a SpriteKit scene within SwiftUI . I created this project initially as a SwiftUI project. Here is the code I have so far: ContentView.swift: /// Where the UI content from SwiftUI originates from. struct ContentView : View { var body: some View { // Scene SceneView().edgesIgnoringSafeArea(.all) } } SceneView.swift: /// Creates an SKView to contain the GameScene. This conforms to UIViewRepresentable, and so can be used within SwiftUI. final class SceneView :

iOS Sprite Kit why can't I repeat colorizeWithColor using white color?

ぐ巨炮叔叔 提交于 2019-12-09 15:28:31
问题 I'm experimenting with ways of selecting sprite nodes using methods other than scale. The one method that I like the most is colorize with white, which highlights the node visibly. However, I cannot seem to be able to replicate the colorize with white behavior more than once. Why can't I apply colorizeWithColor using white color more than once? These two method calls are identical, except for the color used. If I use red, gray, etc, the node responds by flashing for each touch. But If I use

Sprite Kit - Create arch path for SKSpriteNode given a swipe gesture

有些话、适合烂在心里 提交于 2019-12-09 13:54:19
问题 I am making a simple game where the user swipes upward on an object (SKSpriteNode) sending it up and down in an arching motion (using a SKAction I assume). Here's an visual of what I'm hoping to accomplish (please forgive my basic Pixelmator skills): I have created an SKAction which sends the object upwards and calculate the final point of the swipe based on velocity, etc. But, I cannot figure out how to make the arch motion occur once the final point is reached nor fall back to the bottom of

Centering the camera on a node in swift spritekit

安稳与你 提交于 2019-12-09 13:29:59
问题 I am creating a Terraria-style game in Swift. I want to have it so the player node is always in the center of the screen, and when you move right the blocks go left like in Terraria. I am currently trying to figure out how to keep the view centered on the character. Does anyone know of a good way of accomplishing this? 回答1: The below will center the camera on a specific node. It can also smoothly transition to the new position over a set time frame. class CameraScene : SKScene { // Flag

Collect coins and add to score label in Sprite Kit

一个人想着一个人 提交于 2019-12-09 12:22:29
问题 I'm trying to implement a simple scoring system into my game using this tutorial as a reference: http://www.raywenderlich.com/87232/make-game-like-mega-jump-sprite-kit-swift-part-2 The problem is, if I try to implement as is, it crashes in the GameScene.swift on this line: let another = whichNode as! GameObjectNode Here are the main parts of the code where the player collects the coins. I can also invite you to my repo if you'd like to take a closer and better look. I know it can be hard from

How to position child SKSpriteNodes inside their parents

北城以北 提交于 2019-12-09 11:36:37
问题 I don't really understand the logic of positioning child nodes. Lets say I have a rectangle. And if I haven't changed its anchor point, child node will appear exactly in the middle by default. But how to position it on the upper-left edge of rectangle for example? Or down-right? I tried child.zPosition = 1 child.position.y = rect.size.height / 2 rect.addChild(child) But it is not positioned in the middle by Y axis. It's somewhere on top. What instruments should I use to position child nodes

iOS 7.1 Sprite Kit AVAudioSession Crash when enter background

≡放荡痞女 提交于 2019-12-09 07:05:17
问题 So 2 weeks ago I submitted a sprite kit app to the app store and it all was fine. I was having problems before i submitted the app where it would crash because of AvAudioSession, however i was able to fix that problem through this Sprite Kit & playing sound leads to app termination. This basically sets AVAudioSession to inactive when going into background and then active again when coming into foreground. I recently update my phone it iOS 7.1 and this fix doesn't seem to work in the new 7.1