sprite-kit

Receive touch events at SKScene AND SKSpriteNode in SpriteKit

别等时光非礼了梦想. 提交于 2019-12-11 12:55:06
问题 Building a UI with buttons as SKSpriteNode's. Button sprites receive touch events to handle special effects (elastic scaling effects) But I need the SKScene to handle the touch events at the same time to handle UI navigation logic. How would be possible to both (sprite AND scene) to handle these touch events? 来源: https://stackoverflow.com/questions/34987142/receive-touch-events-at-skscene-and-skspritenode-in-spritekit

SKAction repeatActionForever not spawning entity

会有一股神秘感。 提交于 2019-12-11 12:50:13
问题 Basically I have a spawn entity function that should in theory, spawn a random balloon onto the screen with certain properties. I have designed the method as such: -(void)spawnBalloon { int a = arc4random_uniform(self.frame.size.width); int b = self.frame.size.height - 50; CGPoint loc = CGPointMake(a, b); [self spawnBalloonAtPoint:loc]; } And this method works. When I call it in the init function, it works. When I call it in the touchesMoved() function it works. However, when I try and call

SpriteKit. Confusion with applyForce opposite to gravity

无人久伴 提交于 2019-12-11 12:49:23
问题 I use the code listed below as an experiment of SpriteKit. What I do is applying the same amount of force as a gravity effects to it but with anti-parallel vector (mass of body is set to 1.0). The function is executed on each frame via update function. I expect the object not to move at all as applyForce and gravity compensate each other. -(void)didMoveToView:(SKView *)view { self.anchorPoint = CGPointMake(0.5, 0.5); SKShapeNode *node = [SKShapeNode shapeNodeWithRect:CGRectMake(0,0,WIDTH,

Textures used for animateWithTextures getting lost. Some frames show red X

房东的猫 提交于 2019-12-11 12:37:21
问题 My xCode project has the following.... AppDelegate GameViewController OpeningScene MainMenuScene GameScene When the game starts AppDelegate creates an array of all the textures I will use... [self.texturesArray addObject:[SKTexture textureWithImageNamed:@"Background05.jpg"]]; There's about 120 textures. Then I preload them using... [SKTexture preloadTextures:self.texturesArray withCompletionHandler:^{ NSLog(@"************ Finished Preloading Textures in AppDelegate.m *************"); [[STGD

Cannot cast SKNode to subclass of SKNode

大兔子大兔子 提交于 2019-12-11 12:35:42
问题 I am returning an SKNode from one function and I need to cast it to a custom SKNode . I get the error Cannot assign value of SKNode to type GroundNode. If I force cast, it compiles, but fails at runtime. What am I missing? // Custom node class class GroundNode: SKNode { weak var entity: GKEntity! } // Return node function func returnNode() -> SKNode { ... return node } // Where I am getting the error func setupNode() { var ground: GroundNode ground = returnNode() // error here. //// ground =

Easy SpriteKit Contact Detection (Space Shooter Game) Not Wotking Properly

自闭症网瘾萝莉.ら 提交于 2019-12-11 12:24:26
问题 I'm trying to make a simple Space Shooter game. The contact should happen either between the torpedo and the alien or the shuttle and the alien. The problem is that this second contact (shuttle vs. alien) only happens after the first kind of contact has happend (torpedo vs. alien) and further more they're not always precise. This is a struct created outside the class struct PhysicsCategory { static let alien : UInt32 = 1 static let torpedo : UInt32 = 2 static let shuttle : UInt32 = 3 }

swift - dismissing mail view controller from Sprite Kit

落花浮王杯 提交于 2019-12-11 12:08:49
问题 I am trying to add a send email button to a Sprite Kit game. I can get the email dialog to show up. But if I hit cancel, the app will crash or do nothing. If I hit send, the email will send, but the dialog stays. I cannot get the mailComposeController function to fire...please help! Code: import Foundation import UIKit import MessageUI class MailViewController: UIViewController, MFMailComposeViewControllerDelegate { let systemVersion = UIDevice.currentDevice().systemVersion let devicemodel =

Orientation of screen?

痞子三分冷 提交于 2019-12-11 12:08:43
问题 How do I make sure that the only orientations allowed are Portrait or Upside down portrait? I made the change in the project settings, but I'm having trouble making the change in my GameViewController. I need to make the change in this function: override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { if UIDevice.currentDevice().userInterfaceIdiom == .Phone { return .AllButUpsideDown } else { return .All } } However, the "UIInterfaceOrientationMask" structure doesn't

How to display alert view in SpriteKit

↘锁芯ラ 提交于 2019-12-11 11:43:12
问题 I wish to display UIAlertView in my SpriteKit game (saying there is not enough coins to select an item). I have set UIAlertView *alertView; property in my (only) ViewController and initialized it. However I can't access this from my Scene (tried to call a public method but it didn't work). How can I access my ViewController and its properties form the scene? 回答1: As to how to access the ViewController (and its properties) from your SKScene or any SKNode, I would save a pointer inside those

How to change SKAction which is running forever

情到浓时终转凉″ 提交于 2019-12-11 11:40:02
问题 i have an SKAction sequence involving two actions. 1) wait for time according to variable 2) spawn object SKAction *sequence = [SKAction sequence:@[ wait, addObject]]; this action is set to run forever. however, i want the wait duration to change according to updating the variable, but it stays constant as it does not take the new variable when running forever [self runAction:[SKAction repeatActionForever:sequence]]; How do i make it steadily increase the value, therefore increasing the rate