sprite-kit

swift sprite kit game when I shoot on a enemy sometimes the bullet goes trough the enemy, how can I fix this?

浪尽此生 提交于 2019-12-05 07:47:37
问题 I'm making a game in sprite kit (2D) . I have this code: meteor.physicsBody = SKPhysicsBody(rectangleOfSize: enemy.size) and I have a meteor image that you need to destroy but sometimes when I shoot on my device to the meteor the bullet goes through the meteor is this a bug or did I do something wrong? and How can I fix this issue? thanks for reading my problem, I hope someone can help me! if you don't understand my question plz comment what you don't understand. func fireBullet() { let

Specify random particle start colour with no animated change?

我只是一个虾纸丫 提交于 2019-12-05 07:43:42
Is there a way to have particles spawn with a random per particle colour based on the current "Color Ramp"? The particles do not change colour over their lifespan, they are simply assigned a colour from somewhere along the "Color Ramp" at birth and keep that colour until they die. The result of this would be a mix of particles at birth with blend colours from RED through to BLUE. In my tests I only seem to be able to get the behaviour where particles spawn as RED and then gradually turn to BLUE as the approach the bottom of the screen. John Riselvato Well, It looks like you can't use a

Node rotation doesn't follow a finger

假装没事ソ 提交于 2019-12-05 07:04:25
问题 I'm trying to rotate an arrow to follow a finger movement but it performs weirdly. It is definitely not following it. I'm trying to do it in touchesMoved. I tried to do this: var fingerLocation = CGPoint() override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { for touch: AnyObject in touches { fingerLocation = touch.locationInNode(self) let currentOrient = arrow.position let angle = atan2(currentOrient.y - fingerLocation.y, currentOrient.x - fingerLocation.y) let

Slowing down particles of an SKEmitterNode

二次信任 提交于 2019-12-05 06:20:53
问题 I was just curious, is there a way to slowdown particle emitting along the other objects in the scene. Say you have one particle emitter, and one sprite. Sprite is moved using SKAction . An emitter is emitting. Both nodes are added to the scene. If you set self.speed to 0.5, only the sprite will slow down. Emitters will continue emitting at the same speed. Is there a way to slowdown in some other way than using particleSpeed property, because that will change the behaviour of an emitter. My

Gradually change background color in Swift

≯℡__Kan透↙ 提交于 2019-12-05 06:09:30
I'm making a game where I need the background color to change slowly. As the user plays the level, the background color should be changing to show progress. I was thinking of having the starting color be light blue, and then changing to green, then yellow, then orange or something like that over time. Any ideas? Here's a working example, just change the colors: var backgroundColours = [UIColor()] var backgroundLoop = 0 override func viewDidLoad() { super.viewDidLoad() backgroundColours = [UIColor.redColor(), UIColor.blueColor(), UIColor.yellowColor()] backgroundLoop = 0 self

TouchesBegan delay on left hand side of the display

空扰寡人 提交于 2019-12-05 05:52:51
On iPhone's with 3D touch enabled, there is a feature where long pressing the left hand side of the screen with enough force opens lets you change which app is active. Because of this, when a non-moving touch happens on the left hand side of the screen, the touch event is delayed for a second or two until the iPhone verifies that the user is not trying to switch tasks and is interacting with the app. This is a major problem when developing a game with SpriteKit, as these touches are delayed by a second every time a user taps/holds their finger on the left edge of the screen. I was able to

zPosition of SKNode relative to its parent?

半世苍凉 提交于 2019-12-05 05:14:35
I always thought that the the zPosition of a SKNode would be relative to its parent, but right now I'm experiencing the opposite effect. I have two parent SKNodes in my scene, which have a zPosition of 1 (node1) and 2 (node2). What I want to achieve is that node2 should ALWAYS be layered ABOVE node1. But unfortunately, the child nodes of node1 (which have a zPosition of 1-50) are all layered above the child nodes of node2 (which currently have no zPosition). Is there any way to solve this (except giving node2 a zPosition of more than 50)? Maybe some kind of boolean Parameter to set all child

Draw in color the shape of your SKPhysicsBody

时光怂恿深爱的人放手 提交于 2019-12-05 04:47:35
Creating a game with SpriteKit and its actually working out very well. I am using physics and having the ability to see actually where my bodies are because I might have some alpha inside of my sprites will really be helpful. This will also be helpful for creating more precise bodies. In the documentation for SpriteKit they talk about a debugOverlay but the only example they give is to draw the direction of gravity. Here is the link: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html Scroll to area of debugging overlay. Has

How can you connect a swift file with an SKscene?

我与影子孤独终老i 提交于 2019-12-05 04:30:00
问题 I looked through all posts, WWDC talks and youtube videos, but I still can't figure out how to have multiple SKscenes for different levels and connecting them with swift files in a Game using Spritekit. I want to have a main level board and I managed to open a new scene if you press a SKSpriteNode, but how can I implement game logic to this specific SKScene? Apologies in advance if it is a silly question, I've been spending ages on it. 回答1: You can do it like this: 1) Create .swift file and

Confusion about coordinates, frames & child nodes in SpriteKit on iOS?

依然范特西╮ 提交于 2019-12-05 04:22:30
I'm still playing around with learning SpriteKit in iOS & have been doing lots of reading & lots of experimenting. I'm confused by something else I've found* regarding coordinates, frames & child nodes. Consider this snippet of code, in which I'm trying to draw a green box around my spaceship sprite for debugging purposes: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) let debugFrame = SKShapeNode(rect: spaceship.frame)