sprite-kit

Objective-C random position on screen not working properly ( SpriteKit )

妖精的绣舞 提交于 2019-12-12 05:26:55
问题 Well I made a randomNumber Class, (for practice and) for calculating a random position on my screen for an object and it works properly, except for it sometimes puts the sprite out of the screen.The x and y coordinates are smaller the screen height and width. but it doesn't show it on the screen. The whole program is just basically randomly placing instances of an object inside the screen. randomNumber.h #import <Foundation/Foundation.h> #import <SpriteKit/SpriteKit.h> @interface randomNumber

Extend SKAction to override timingMode

本小妞迷上赌 提交于 2019-12-12 05:19:46
问题 I have many SKActions in a SpriteKit project. The default timingMode for SKActions is "linear". Is it possible to use an extension to override this timingMode default to e.g. "easeInEaseOut" so ALL SKActions have timingMode = easeInEaseOut? I have tried various "extension" styles but none will compile - normally returning "'timingMode' used within its own type" or "Initializer 'init()' with Objective-C selector 'init' conflicts with implicit initializer 'init()' with the same Objective-C

iOS - How to scroll horizontally in sprite kit

让人想犯罪 __ 提交于 2019-12-12 05:03:14
问题 I have a SKSpriteNode that is too big for the view and I am looking for a simple way in Sprite Kit to scroll horizontally to be able to see it completely. Thanks! 回答1: You could try using an SKCameraNode and respond to a pan gesture like so: // GameScene.swift override func didMove(to view: SKView) { self.camera = SKCameraNode() let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePanFrom(recognizer:))) panGestureRecognizer.maximumNumberOfTouches = 1

SKPhysicsBody malloc error

大城市里の小女人 提交于 2019-12-12 04:59:52
问题 I created a subclass called Obstacle of SKSpriteNode and implement the physics body in the init : -(id)initWithHeight:(NSInteger)height flipped:(BOOL)flipped { if (self = [super initWithImageNamed: @"obstacle.png"]) { [self setName: @"obstacle"]; [self setSize: CGSizeMake(OBSTACLE_WIDTH, height)]; [self setPosition: CGPointZero]; // rotate if needed if (flipped) { [self runAction: [SKAction rotateByAngle: 3.14 duration: 0.0f]]; } // physics SKPhysicsBody* pb = [SKPhysicsBody

Passing data from one SKScene to the next

老子叫甜甜 提交于 2019-12-12 04:55:43
问题 So I am designing a game. In my MenuScene class I have the following: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { SKTransition *transition = [SKTransition fadeWithColor:[UIColor colorWithRed:147.0/255.0 green:213.0/255.0 blue:216.0/255.0 alpha:1.0] duration:2.0f]; MyScene *gameScene = [MyScene sceneWithSize:self.size]; [self.view presentScene:gameScene transition:transition]; } Which transitions to the game scene. I need to pass some data to the game scene. In the game

interstitialAd will not show up

天涯浪子 提交于 2019-12-12 04:54:47
问题 i´ve created a SK Game with one viewController and want to view full screen ads but they don´t show up. in ViewController.m: (viewWillAppear) self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual; [self requestInterstitialAdPresentation]; inAppDelegate.m: [ViewController prepareInterstitialAds]; 回答1: Your approach looks correct, and you are right that you only need those method calls, You may just need to move: [self requestInterstitialAdPresentation]; into

How to have Billiards like physics in SpriteKit?

筅森魡賤 提交于 2019-12-12 04:23:30
问题 I'm new to SpriteKit and am trying to make a Billiards game but it just doesn't seem to be working properly. The balls don't bounce off each other or the pool cue. I'm not sure what I'm doing wrong. Here is some sample code of one of the balls and the pool cue. Any help will be appreciated! class PoolTableScene: SKScene, SKPhysicsContactDelegate { struct PhysicsCatagory { static let None : UInt32 = 0 //0 static let PokeBall : UInt32 = 0b1 //1 static let PoolCue : UInt32 = 0b1000 //5 static

Accessing element in array, saving it and overwriting it

爱⌒轻易说出口 提交于 2019-12-12 04:14:07
问题 My Goal: to access an element in an SKnode array and its property between my two scenes and also save and retrieve it the array that contains my achievement SKNodes that hold different values. So I have two scenes one that is my actual game scene and the second one being my achievements menu that contains the list of all my achievements. When the achievementMenu scene starts it produces 27 Achievements which are a subclass of SKNode called “Achievements” which is seen below” It is made in a

Load a .tmx (Tiled Map) in Sprite Kit?

╄→гoц情女王★ 提交于 2019-12-12 04:05:24
问题 Is there a (preferably easy) way to load a .tmx file in iOS 7's Sprite Kit? If not, are there any alternatives? 回答1: Check out TilemapKit for Sprite Kit. Unlike other solutions it loads and renders all (!) map types and variations supported by Tiled, including staggered iso and hex maps! TilemapKit is properly engineered like a OOP framework should be, and exposes all data that is stored in the TMX file. In other words it's definitely not just a single class that got everything crammed into

cancelling a tap gesture recongiser

早过忘川 提交于 2019-12-12 04:05:12
问题 Referring to my last question: Sprite moves two places after being paused and then unpaused Hi, I have a tap gesture which moves a sprite in my game forward 1 space and when I press the pause button it continues to register the tap gesture and then when I resume the gameplay It moves two spaces. so I managed to define a bool variable that detects (using if statements) if I have paused the tap gesture var tapIsPaused: Bool = false func tapUp(){ if(tapIsPaused == true) { //do nothing } else if