sprite-kit

Universal 2D Game Assets and Absolute Node Positioning

谁都会走 提交于 2019-12-20 18:29:45
问题 I have a question regarding universal game assets and absolute positioning of a SKNodes in Sprite Kit (iOS 8+). I will try to present my problem through an example as follows : Imagine a 2D top down game with a SKSpriteNode which represents a house. A house has multiple child SKSpriteNode s which represent chairs, desk, sofa, etc. I have 3 versions of house asset: 1x - 200 x 200px (Non-retina iPads), 2x - 400 x 400px (Retina iPhones and iPads), 3x - 600 x 600px (iPhone 6 Plus). Important :

A count of started touches is not equal to count of finished touches

巧了我就是萌 提交于 2019-12-20 17:39:12
问题 I have the following code for testing purposes: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self customTouchHandler:touches]; } - (void)customTouchHandler:

Endless scrolling (repeating) background in Spritekit game - Swift

时光怂恿深爱的人放手 提交于 2019-12-20 12:38:40
问题 I want to Create a endless scrolling background for my spritekit game, iT should consist of one or two images probably, which repeat themselves? I found these one and two examples, but they are in obj. C. I have no idea how I can achieve this in Swift. And is it possible to set the speed manually? Ps: I don't have the skill to convert obj. C into swift (newbie to Xcode dev.) 回答1: I found a way to do this, somehow i managed to convert this obj. C to swift You have to declare the two node's

SpriteKit: Preload sound file into memory before playing?

你说的曾经没有我的故事 提交于 2019-12-20 12:29:16
问题 Just wondering if this is possible. Currently, the first time I play a sound file while the app is running, there is a noticeable delay before the sound actually plays (like it's caching it or something). After this it plays instantly without issue, but if I close the app completely and relaunch it, the delay will be back the first time the sound is played. Here is the code I'm using to play the sound: [self runAction:[SKAction playSoundFileNamed:@"mySound.caf" waitForCompletion:NO]]; 回答1:

Keep SKNodes from applying force to each other

非 Y 不嫁゛ 提交于 2019-12-20 07:37:08
问题 I have two SKNode objects. Their positions change when they collide. How can I prevent that? At the same time, I still want to be able to respond to them contacting via - (void)didBeginContact ; I tried setting both their mass property to 0.0f but that didn't work. 回答1: You can achieve that by setting category, collision and contact bit masks. uint32_t bodyABitMask = 1<<0; uint32_t bodyBBitMask = 1<<1; //A mask that defines which categories this physics body belongs to. [bodyA

Keep SKNodes from applying force to each other

我的梦境 提交于 2019-12-20 07:37:03
问题 I have two SKNode objects. Their positions change when they collide. How can I prevent that? At the same time, I still want to be able to respond to them contacting via - (void)didBeginContact ; I tried setting both their mass property to 0.0f but that didn't work. 回答1: You can achieve that by setting category, collision and contact bit masks. uint32_t bodyABitMask = 1<<0; uint32_t bodyBBitMask = 1<<1; //A mask that defines which categories this physics body belongs to. [bodyA

How to Fit the Physics Body Size of an SKSpriteNode to its Image in Xcode Using SpriteKit

╄→尐↘猪︶ㄣ 提交于 2019-12-20 07:20:58
问题 So I'm not sure if this is possible, but I am trying to adapt the physics body to go with my image. Many people have told me that the hitbox for the character in my game on the iOS App Store (StreakDash - go download it!) does not work well, since it makes the game a lot harder (the hitbox hits an obstacle even though the character doesn't appear to even be touching it). This is due to the fact that the hitboxes are rectangular, whereas my character has a strange shape. Are there any ways to

SKAction playSoundFileNamed failed at 500 mp3

回眸只為那壹抹淺笑 提交于 2019-12-20 07:09:35
问题 In my application I need to use a lot of short different mp3s (about 500 items one by one) So I use SKAction playSoundFileNamed After ~200 sounds it crashed with 'Failed to load resource - Resource s234.mp3 can not be loaded'. Memory rises to 70mb. How to avoid this? What I tried: recreate sound in every iteration SKAction *mySound=[SKAction playSoundFileNamed:aa waitForCompletion:YES]; create the one variable in the beggining of .m SKAction *mySound; and reuse it in iterations mySound=

SpriteKit - How to fix distortion in Node's animation?

不打扰是莪最后的温柔 提交于 2019-12-20 05:47:24
问题 I have created an animation of various PNGs, but there are various frames that stretch to the border so the node is 'filled'. The animation should look like the GIF that I have created using the same pictures. Does anybody know how to make the animation look like the GIF? GIF: Gif: Animation should look like this Actual: Extra slow Actual result of the code Border: Here you can see the border of the physics body that has the same size of the "node's border" I have tried to fix the problem by

Randomizing node movement duration

若如初见. 提交于 2019-12-20 05:30:34
问题 I am making a game in SpriteKit and I have a node that is moving back and forth across the screen and repeating using the code: let moveRight = SKAction.moveByX(frame.size.width/2.8, y: 0, duration: 1.5) let moveLeft = SKAction.moveByX(-frame.size.width/2.8, y: 0, duration: 1.5) let texRight = SKAction.setTexture(SKTexture(imageNamed: "Drake2")) let texLeft = SKAction.setTexture(SKTexture(imageNamed: "Drake1")) let moveBackAndForth = SKAction.repeatActionForever(SKAction.sequence([texRight,