sprite-kit

SpriteKit: touchesEnded/ mouseUp sent to released object

六月ゝ 毕业季﹏ 提交于 2019-12-12 02:42:08
问题 I have the problem that touchesEnded (on iOS) or mouseUp (on macOS) is still called on released objects when the touch/click was started before the release. This behavior is causing crashes in my project. I made a stripped down program with SceneKit and a SpriteKit overlay but I am not sure what I am doing wrong. I've started with the SceneKit game template (iOS or macOS) and I've added two classes: In GameViewController.m at the end of -(void)awakeFromNib I added this: OverlayScene *overlay=

After Showing Interstitial Ad when GameOver, scene return to WelcomeScene

一曲冷凌霜 提交于 2019-12-12 02:32:52
问题 I have a sprite kit game and I want to show interstitial ad when the game is over. Well, I am able to show the ad after when the game over using NotificationCenter but the problem is that when the I close the ad, it returns to the WelcomeScene. I want to return to the GameOverScene after closing the ad but how? GameViewController.swift import UIKit import SpriteKit import GameplayKit import GoogleMobileAds class GameViewController: UIViewController , GADInterstitialDelegate { var

Change height of an SKShapeNode

本小妞迷上赌 提交于 2019-12-12 01:58:27
问题 I have an SKShapeNode which moves down when a sprite gets close to the top of the screen. However I can't seem to change the height of the frame. Changing the property directly gives me the error 'Expression is not assignable'. So I tried this code: //Move the world down world.position = CGPointMake(0.0f, -(20.0f)); SKAction* moveDown = [SKAction moveToY:(world.position.y - 50.0f) duration:1]; [world runAction:moveDown]; CGRect temp = world.frame; temp.size.height = (world.frame.size.height /

SKPhysicsJointPin pin position

拥有回忆 提交于 2019-12-12 01:56:26
问题 I'm trying to understand SKPhysicsJointPin a bit better, specifically the anchor point parameter. I understand that the anchor point is the position in the parent node of the two physics bodies concerned. What I don't understand at which point in the participating bodies does the pin go through and if there is a way to control that. To make myself clear, say I'm making a clock with hands so the pin should go in the middle of the circle but for the hands is should go through the edge. So how

spritekit: trouble with particle keyframe sequence

房东的猫 提交于 2019-12-12 01:49:41
问题 This should be really straightforward. I'm trying to have my particles fade out using a keyframe sequence.. but when I use the keyframe sequence they dont fade out at all. Not sure what I could be doing wrong. particle creation: static func debris(size: Int) -> Array<SKEmitterNode> { if size > 5 { fatalError("we don't have that much debris") } var debrisArr: [SKEmitterNode] = [] for i in 1...size { let debris: SKEmitterNode = SKEmitterNode(fileNamed: "debris") debris.particleTexture =

Spritekit rotate a node while touching

扶醉桌前 提交于 2019-12-12 01:49:01
问题 I'm currently working on some sort of top down racer if you will. The idea is to have two buttons, each for turning a car left or right. This all works, but it only works with one touch. I'd like to have the player turn the car by simply holding down the button. I now have -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ for (UITouch *touch in touches) { touched = YES; CGPoint location = [touch locationInNode:self]; SKNode *node = [self

How to disable anti-aliasing in SKLabelNode?

丶灬走出姿态 提交于 2019-12-12 01:38:48
问题 I want to use a pixel font in my SpriteKit game. But I can't use a bitmap font because I need to support many languages (too many characters). So I should use a ttf font file. I tried the following code, but characters were blurred by anti-aliasing. let myLabel = SKLabelNode(fontNamed:"My-Pixel-Font") myLabel.text = "Hello" myLabel.fontSize = 10 myLabel.position = CGPoint(x: 100.0, y: 100.0) myLabel.fontColor = SKColor.GrayColor() self.addChild(myLabel); Is there a good way to disable anti

Taking an array option out for one cycle

雨燕双飞 提交于 2019-12-12 01:36:17
问题 Ok so I have this code where spawn locations are put into an array and then one of the locations is picked at random with this code: let randx = spawnLocations[Int(arc4random_uniform(UInt32(spawnLocations.count)))] obstacle.position = CGPoint(x: randx, y: 0) Object Spawning code: var spawnLocations:[CGFloat] = [] func getObjectSpawnLocation() { //Create 5 possible spawn locations let numberOfNodes = 5 // Spacing between nodes will change if: 1) number of nodes is changed, 2) screen width is

SpriteKit: how to turn touches into vectors of uniform speed?

江枫思渺然 提交于 2019-12-12 01:28:26
问题 I am using touches to set SpriteKit nodes in motion. Currently I do this: //(previous code turns current touch and last touch into thisP and thatP)... CGPoint velocity = CGPointMake(thisP.x - lastP.x, thisP.y - lastP.y); //If the velocity is non-zero, apply it to the node: if (!CGPointEqualToPoint(velocity, CGPointZero)) { [[MyNode physicsBody] applyForce:CGVectorMake(velocity.x, velocity.y)]; } This is very effective at getting the nodes to move different speeds depending on how fast the

Function to run a wait action at decreasing intervals indefinitely

社会主义新天地 提交于 2019-12-12 01:25:47
问题 I have code which runs a wait action for a duration of columnTime and then runs a block of code. This results in the block running once, then wait time, then block, then wait time, etc. func startSpawning(){ print(columnTime) let wait = SKAction.waitForDuration(columnTime) let block = SKAction.runBlock({[unowned self] in self.spawnObstacle()}) let sequence = SKAction.sequence([wait, block]) runAction(SKAction.repeatActionForever(sequence), withKey: "spawning") } //startSpawning I want the