sprite-kit

Why is there multiple collision calls Sprite Kit Swift

有些话、适合烂在心里 提交于 2019-12-08 02:21:42
问题 I am building an iOS swift game with collision. The hero is being bombarded by small stars coming from the right side of the screen. Every time a star hits the hero, the score is iterated and the star is removed. But, more than one point is added to the score. Node Set-up: var star = SKSpriteNode(imageNamed: "star") star.size = CGSizeMake(30, 30) star.zPosition = 10 var starPhysicsRect = CGRectMake(star.position.x - star.frame.size.width / 2, star.position.y - star.frame.size.width / 2, star

SKLabelNode text with two different fonts and colour. How is this possible?

谁说胖子不能爱 提交于 2019-12-08 02:05:16
问题 I have an SKLabelNode which is set up to show the Score Variable followed by the Highscore variable scoreLabel.text = "\(score)/\(classicHScoreInt)" Now, everything shows fine but i would like the classicHScoreInt to be a smaller font and maybe a different colour. How is this possible? classicHScoreInt is (as stated) an integer and so is score 回答1: You cannot set two fonts to the same SKLabelNode instance. Instead you can write subclasses to create a custom node which contains multiple

How to add an .sks files to existing Swift/Sprite-Kit project?

徘徊边缘 提交于 2019-12-08 01:57:35
问题 I started following Ray Wenderlich's 'Space Invaders' tutorial, but have diverged considerably. I now have 3 SKScenes - my title screen, my main game screen and my end level/game over screen. The title screen and the end game scene I added and these both have .sks files; the main game screen does not and all elements (SKSpriteNodes etc) are placed programatically. The flow of my program is as follows: I now would actually like to place some events of the main game screen via the scene editor,

Sprite Kit crash when running an action/loading an asset on only iPad Air and iPad mini with Retina

╄→гoц情女王★ 提交于 2019-12-08 01:52:33
问题 I'm getting crash reports which are coming from retina mini and iPad Air devices, but not iPhone 5S. It occurs in SpriteKit when someone taps on a sprite which is supposed to then make another show up on screen. I'm not able to reproduce this on a non-A7 device so wondered if anyone can take a look at the crash log below and let me know what the crash may be caused by? Exception Type: SIGSEGV Exception Codes: SEGV_ACCERR at 0xb000000c Crashed Thread: 0 Thread 0 Crashed: 0 libobjc.A.dylib

SpriteKit game crashes when two SKPhysicsContacts are detected

旧街凉风 提交于 2019-12-08 00:41:03
问题 I have a SpriteKit game where you must shoot down asteroids before they hit the base. But if you shoot and hit the asteroid and/or the base when the asteroid is hitting the base, the program crashes. Here's my physics contact code. public func didBegin(_ contact: SKPhysicsContact) { //Asteroid is object 1, other item is object 2 var object1 = SKSpriteNode() var object2 = SKSpriteNode() //Test for asteroid/projectile contact, then remove appropriate sprites, change game values and play sounds

Making SKLabelNode as a crop node of SKShapeNode

对着背影说爱祢 提交于 2019-12-08 00:12:14
问题 Can't find in web, how to make SKLabelNode cropping SKShapeNode. When i colorize the background, my goal is colorize the label too with the same method, so both of them have to colorize simultaneously. But can't imagine how to crop SKShapeNode with this label. Help me please! 回答1: But can't imagine how to crop SKShapeNode with this label. If I understand you correctly, you can set SKLabelNode as a mask of a SKCropNode, like this: override func didMoveToView(view: SKView) { backgroundColor =

How do I convert a PNG with alpha to RGBA4444 for using it in SpriteKit SKTexture?

家住魔仙堡 提交于 2019-12-08 00:04:24
问题 I have a stack of transparent PNGs that I'd like to use in a SKSpriteNode animation with SKTexture s. I'd need to adjust the memory usage of SKTexture s by reducing texture quality down from RGBA8888 to RGBA4444 . How would I initialize SKTexture with RGBA4444 texture format? Edit: IOS Swift Game Development Cookbook: Simple Solutions for Game Development suggests that SKTexture would support PVRTC files as follows: However, I couldn't get a SKSpriteNode to display a texture generated this

SKshapenode is not responding to Physicsbody

社会主义新天地 提交于 2019-12-07 22:55:28
问题 I have created a SKShapeNode and I have assigned a physicsBody to it. However, it is not being triggered when there is contact. Creation of SKShapeNode code: -(SKShapeNode*)gravityline{ //SKSpriteNode *lolo=[[SKSpriteNode alloc]init]; SKShapeNode *lolo = [[SKShapeNode alloc] init]; CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, fff.x, fff.y); CGPathAddLineToPoint(path, 0,rayoriginpoint.x,rayoriginpoint.y

SKAction.colorizeWithColor makes SKLabelNode disappear

眉间皱痕 提交于 2019-12-07 22:51:31
问题 I'm using SKLabelNode. I'm creating it and add it to my scene as a child and it displays with no problem, but when I try to change it's color (not fontColor) with the colorizeWithColor() method the label fades out. Here is the line with the problem: myLabel.runAction(SKAction.colorizeWithColor(SKColor.blueColor(), colorBlendFactor: 1.0, duration: duration)) I printed to the console the myLabel.color property after the completion of this action and here is what I get: Optional

Pausing game in Sprite Kit: Why doesn't this work?

送分小仙女□ 提交于 2019-12-07 22:28:24
问题 So I added a pause button to my game and the freezing and unfreezing of the view works. However I want it to display a message saying "PAUSE" over the screen if the view is currently frozen. But if I'm touching my pause button it doesn't display the label. It's really strange, because I discovered that if I'm turning my device to landscape mode, the "PAUSE" message appears. (and vice versa too, so if I touch the button in landscape mode and turn my device to portrait, the pause label appears)