sprite-kit

Gap between SKSpriteNodes in SpriteKit collision detection

点点圈 提交于 2019-12-10 16:55:01
问题 I've been trying to figure this out for quite a while now -- I have a game with simple platformer physics where a player falls onto a block, which stops him from falling. This works, however there is a noticeable gap between where the player stops, and where the actual object/spritenode is. Here is a screenshot, it should be self-explanatory: class GameScene: SKScene { override init(){ super.init(size: UIScreen.mainScreen().bounds.size) self.physicsWorld.gravity = CGVector(dx: 0, dy: -9.8) }

Objective-C: Adding 10 seconds to timer in SpriteKit

Deadly 提交于 2019-12-10 16:51:08
问题 I used someone else's code for writing a timer in SpriteKit, and tweaked it a bit. Here's what my code looks like: - (void)createTimerWithDuration:(NSInteger)seconds position:(CGPoint)position andSize:(CGFloat)size { // Allocate/initialize the label node. _countdownClock = [SKLabelNode labelNodeWithFontNamed:@"Avenir-Black"]; _countdownClock.fontColor = [SKColor blackColor]; _countdownClock.position = position; _countdownClock.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;

Spritekit: First texture draw slow (preloaded)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 15:39:16
问题 I'm having a performance issue regarding Apple Spritekit Framework. I use the method preloadTextureAtlases:withCompletionHandler: of SKTextureAtlas to make sure all my textures are loaded before the game really starts. Yet when the first texture of this atlas (whatever it is) is added to the scene as a child I got a small lag, like if the texture wasn't loaded. It only happens the first time . I tried real hard to debug this and to find the reason but I couldn't find it. Looking with

iOS 9 / Xcode 7: SKSpriteNode spriteNodeWithImageNamed not working on some devices

戏子无情 提交于 2019-12-10 15:38:50
问题 I am having problems to load a image from a .xcassets imageset for a SKSpriteNode. While it worked fine on iOS 8.x with [SKSpriteNode spriteNodeWithImageNamde:imageName] it doesn't work on some devices on iOS 9. For example it works on iPhone 6/6 Plus and iPad Air but not on the iPod Touch 5G. Works on all devices with iOS 8.x but not on all devices (for example iPod Touch 5g) on iOS 9.x (Xcode 7, Xcode 7.1 Beta 3): SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@

Horizontal scrolling in SpriteKit (vs. a viewcontroller)

人走茶凉 提交于 2019-12-10 15:22:41
问题 I'm a little confused about the right way to approach this: In my game, I allow the player to choose from 5 areas to play. An area is nothing more than a rectangle on a screen with the % of your completion in that area. The entire list is centered and looks good. ..Eventually there will be more areas but I don't want them to be on multiple rows (I'd like the player to swipe to scroll through them). To date, all of the features of my game have been cone using SpriteKit (I only have one view

Getting the filename of an SKSpriteNode in Swift 3

亡梦爱人 提交于 2019-12-10 14:59:19
问题 How can I access the image filename from an SKSpriteNode ? I have been trying to Google this, but no answer seems to be available. Here is the impotent part of my code: current_ingredient?.name = String(describing: current_ingredient?.texture) print("Filename: \(current_ingredient?.name)") The print command returns this: Filename: Optional("Optional(<SKTexture> \'ingredient14\' (110 x 148))") So, the question is, how do I get only "ingredient14"? 回答1: It is stored in the description, so here

How To Create a Pulse Effect On an SKSpriteNode?

房东的猫 提交于 2019-12-10 14:56:36
问题 Hi would like to learn how to create a visual pulse effect as in the video below. https://www.youtube.com/watch?v=uiHj-KZWjpU I followed the link posted in the video; however, I have not been able to achieve the same effect. I am having trouble doing it with an SKSpriteNode. Preferably I would like to be able to loop this effect to repeat every second or so. Any help would be very much appreciated! Thanks! 回答1: A real easy way of doing this would be to have your button image, and an outline

Sound resource can not be loaded Swift SKAction

时间秒杀一切 提交于 2019-12-10 14:49:34
问题 I have an app that plays a sound file every time the screen is touched. For some reason, the app will crash every once in a while with the following error: reason: 'Resource tick.mp3 can not be loaded' In case you need it, here is how I play the file each time the screen is tapped: runAction(SKAction.playSoundFileNamed("tick.mp3", waitForCompletion: false)) This does not happen very often, maybe 1 in 10 runs of the app. Most of the time everything works as expected. I wish I knew what I am

SKAction sequence temporary delay (initial delay?)

老子叫甜甜 提交于 2019-12-10 14:07:29
问题 So in the game I'm building I want to repeat an action, but I want it to have an initial delay. So for example, the action would execute three seconds after the user started the game, but after it executes for the first time, there's no longer a three second delay. What can I do to solve this? Thanks in advance! 回答1: You could use an SKAction to make a delay, then put it at the beginning of your sequence . Apple gives some sample code on sequences: SKAction *moveUp = [SKAction moveByX:0 y:100

Home button press causes EXC_BAD_ACCESS code=1 in SpriteKit SKView

爱⌒轻易说出口 提交于 2019-12-10 13:28:30
问题 SpriteKit is supposed to clean up and pause all timers when you press the home button. However, we have found that if you single tap the home button while displaying an active SKView, the app crashes. This occurs even if that view is already paused by the user. Strangely, if you double tap the home button and move to the multitasking view, everything works fine. Follow Up Note: The simulator works perfectly in both situations, no crash Is anyone else seeing this issue with SpriteKit? Have you