sprite-kit

Align multiple SKLabelNodes by Baseline

╄→尐↘猪︶ㄣ 提交于 2019-12-11 01:11:10
问题 I have a collection of SKLabelNodes . Each node represents a letter of a word. Each node is the child of an SKSpriteNode . The spriteNode has an explicit hight set on it (the hight returned by [text sizeWithAttributes:@{NSFontAttributeName : font}]; ), and has the same width as the labelNode . The labelNode is then centred inside the spriteNode , and has verticalAlignmentMode = SKLabelVerticalAlignmentModeBaseline . At a later stage, I will need to set a background image on each letter (which

calculate the angle between a line and x-axis

女生的网名这么多〃 提交于 2019-12-11 00:57:33
问题 I have two points in my coordinate system (x,y) that I want to know the angle of their line and x-axis. I use swift for solving this but I can't get the angle. I need this angle in radians to use it in the following equation: (x0 + r cos theta, y0 + r sin theta) r : radius of circle 回答1: If you have two points, (x0, y0) and (x1, y1) , then the angle of the line joining them (relative to the X axis) is given by: theta = atan2((y1 - y0), (x1 - x0)) 回答2: The angle between a line, for reference,

Trying to use only a portion of a SKTexture using textureWithRect inTexture

自闭症网瘾萝莉.ら 提交于 2019-12-10 23:55:13
问题 What I'm doing is create a SKTexture based on the full image SKTexture *fullTexture = [SKTexture textureWithImageNamed:@"fullImage"]; I want to use the full width of the fullTexture, but only a portion of height of the texture, BUT, starting from the TOP of the full image. After figuring out that the width seems to be in percentage, I used the following code: SKTexture *croppedTexture = [SKTexture textureWithRect: CGRectMake(0,0,1,percentageY) can somebody give me the correct float values for

How to stop my character from over rotating with zRotation constraints?

邮差的信 提交于 2019-12-10 23:31:04
问题 I have a vehicle in a platformer game I'm working on that I want to be able to allow rotation so it can roll up hills and such. I want to limit my vehicle to 30 degrees rotation in the negative and positive direction. The issue is when i have rotation enabled and roll off of a cliff or straight edge drop off, my vehicle flips over off the side and lands on its head. I've been searching for a way to limit the zRotation to a set number of degrees in each direction. I tried using the IK

SKLabelNode without transparent background

故事扮演 提交于 2019-12-10 23:28:25
问题 Hi I'm using a custom font on a SKLabelNode. I'm able to set the font colour but ok, but the inner parts of the text, are transparent. Is there a way i can set this colour to white for example? my code so far scoreLabel.fontColor = [SKColor colorWithRed:0.0 green:0 blue:0.0 alpha:1.0]; 回答1: The easiest way I found is to combine an SKSpriteNode and a SKLabelNode. You simply add the SKLabelNode as a child to the SKSpriteNode. SKLabelNode *label = [[SKLabelNode alloc]initWithFontNamed:@"Courier"

Having issues with creating Tile Sets in Xcode 8. Anyone have any success?

风格不统一 提交于 2019-12-10 22:57:59
问题 Been trying to create a tile set to use in the new scene editor in the Xcode 8 beta. But, I drag a image in there from the asset catalog and I click away and it's as if I never placed a texture in there. I can't figure out how to get the tiles to save the image data. Before: After I click away to any other file then click back: Then the Scene Editor won't let me select a tile to use to draw. Anyone had any luck saving image data in a tile and using it? Any workarounds? Anyone able to upload

Atlas images wrong size on iPad iOS 9

狂风中的少年 提交于 2019-12-10 22:31:11
问题 Since upgrading to iOS 9 I have this strange issue with image atlases in my SpriteKit game. In my game I have a StartScene, a MenuScene and a GameScene. In all 3 scenes I am using atlases for my enemies so I can animate them. All worked fine on all devices but since upgrading iOS 9 it causes me issues on iPads. On my iPad when I launch the game the enemies in StartScene are about 3 times as big as they should be. Whats strange is that when I move to menuScene or gameScene the enemies are

Leaving equal width gap spacing before and between menu buttons

余生颓废 提交于 2019-12-10 22:24:10
问题 I have created a scrolling menu using the code below. I am trying to create equal row gaps (width spacing) between each of the menu sprite buttons. Currently, I've been able to leave equal width spacing at the left and right ends but not in between sprite buttons. Please see the relevant code below: class LevelScene: SKScene { let levelButtonSize = SKSpriteNode(imageNamed: "b1").size let levelButton1: SKSpriteNode = SKSpriteNode(imageNamed: "b1") let levelButton2: SKSpriteNode = SKSpriteNode

Large texture atlas causes termination due to memory pressure

一世执手 提交于 2019-12-10 22:07:54
问题 I'm designing a game in iOS Swift. I have a large texture-atlas of about 100 1920x1080p PNG's. When I call the functions it crashes the app due to memory pressure. When I disable the function my app runs just fine. Can I prevent this crash by editing my code or is my texture-atlas just too big? Code: var waterWave: SKSpriteNode! var waterWalkingFrames : [SKTexture]! func addWater() { let waterAnimatedAtlas = SKTextureAtlas(named: "water.atlas") var waterFrames = [SKTexture]() let numImages =

Any way to speed up gameplay gradually in Swift?

爱⌒轻易说出口 提交于 2019-12-10 21:17:12
问题 I'm currently working on a game using Spritekit. The game has objects which spawn at the top of the screen and fall towards the player character, and the game ends when the player character collides with any of the objects. I am trying to find a way to gradually speed up gameplay over time to make the game more difficult (i.e. objects fall at normal speed when the game begins, after 5 seconds speed up 50%, after 5 more seconds speed up another 50%, ad infinitum.) Would I need to use NSTimer