sprite-kit

sprite kit collisions: ignore transparency?

倖福魔咒の 提交于 2019-12-06 06:13:59
I am building a game with Xcode's spritekit. Its a platform game and right now it functions well with flat ground pieces. I was wondering if it was possible to ignore transparency in the png for collisions. That is to say, If i have a ground piece with a curved floor and transparency filling the troughs, can i make the player walk the curves instead of a square bounding box covering the whole thing? The only example i can find is in the Gamemaker GML language, you can do "precise" collisions such that blank space in the images do not count as part of the sprite. I can supply code if necessary

does swift not allow initialization in function parameters?

為{幸葍}努か 提交于 2019-12-06 06:10:58
This first block generates a generic Swift Compile Error (doesn't even point to the line) let screenDivision = size.width / 5; var game1 = SKSpriteNode(color: .redColor(), size: CGSize(width: 2 * screenDivision, height: size.height)); This second block works fine. let screenDivision = size.width / 5; var a = CGSize(width: 2 * screenDivision, height: size.height) var game1 = SKSpriteNode(color: .redColor(), size: a); Why? I'd hate to run into this error again and not remember where I wrote such code. (I also need to pass it a variable, not a constant? Wtf... [if I change var a, to let a, I get

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

[亡魂溺海] 提交于 2019-12-06 06:06:56
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 way. Luca Angeletti I just tried and in Xcode 8 the option Output Texture Atlas described here is no

SKPhysicsContact Not Detecting categoryBitMask Collision

杀马特。学长 韩版系。学妹 提交于 2019-12-06 05:45:43
So I have my "Floor.swift" class below which is basically a bunch of walls. I have objects coming from the top of the screen and once the Floor and SKSpriteNodes collide, I'd like the SKSpriteNode to be removed. Below is my Floor class. import Foundation import SpriteKit class Floor: SKNode { override init() { super.init() let leftWall = SKSpriteNode(color: UIColor.brown, size: CGSize(width: 5, height: 50)) leftWall.position = CGPoint(x: 0, y: 50) leftWall.physicsBody = SKPhysicsBody(rectangleOf: leftWall.size) leftWall.physicsBody!.isDynamic = false self.addChild(leftWall) let rightWall =

How to reverse the direction of path followed by sprite in an SKAction midway?

走远了吗. 提交于 2019-12-06 05:44:32
I have a SKSpriteNode which is moving along a circular path using an SKAction : // create the path our sprite will travel along let circlePath = CGPathCreateWithEllipseInRect(CGRect(origin: pathCenterPoint, size: CGSize(width: circleDiameter, height: circleDiameter)), nil) // create a followPath action for our sprite let followCirclePath = SKAction.followPath(circlePath, asOffset: false, orientToPath: false, duration: 2 I can add .ReversedAction() to reverse the direction of the sprite, but that will only happen from the starting point. How do I reverse the direction of the sprite, when its at

Presenting a UIViewController from an SKscene (SpriteKit)

纵饮孤独 提交于 2019-12-06 05:42:32
There are several posts on the internet asking how to correctly combine SpriteKit and Storyboard/Interface builder. In particular nobody is able to move from an SKscene to a desired UIViewController. NONE of the solutions on the net really address this problem! Is it really not possible to do this?? If so, it would be a significant limitation of SpriteKit... You cannot move directly from an SKScene to another UIViewController . However, the SKScene is already contained in a UIViewController . You can use delegation to pass a method call from the scene to its controller. The controller can then

Is there a way to create a concave physicsBody in SpriteKit?

狂风中的少年 提交于 2019-12-06 05:39:05
I have an object on scene and my hero should not go through it, but it should be able to go inside of it, like a boat into the bay, surrounded by the other element. I tried all kinds of physicsBody having it have body with rectangle, texture, with polygon from path, but to no avail. I was reading somewhere that it is not possible to have a concave physicsBody, but only convex. I really need it to be able to be concave. Does anyone know how to resolve this? You can create a concave physics body by adding up a bunch of convex physics bodies into one shape. Then you can add them as children to an

Swift: How to convert a particle network JS animation to iOS

久未见 提交于 2019-12-06 05:27:36
问题 I found this javascript animation: JS animation I really want to know how I can convert animations like this to use it in my Swift iOS app. Has anybody got experience in likely things? I found things like spritekit, but I really can't find the right info/tutorials about this. Maybe someone does know what I should do/look up? Hope anybody can help me, thanks in advance! 回答1: Use a customView to upgrade their js codes to swift. Hope it is the answer. Beware of the copyright when you use their

SpriteKit game crashes when two SKPhysicsContacts are detected

∥☆過路亽.° 提交于 2019-12-06 05:13:45
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 if contact.bodyA.contactTestBitMask == ColliderType.Asteroid.rawValue && contact.bodyB

How to make a Toggle Button on SpriteKit

半腔热情 提交于 2019-12-06 05:07:02
问题 I am doing a sound toggle button in SpriteKit, and I'm trying to find out a quick way to do it. I remember that in Cocos2d there was a variable called CCMenuItemToggle that made all the stuff, for example: CCMenuItemToggle* musicButtonToggle = [CCMenuItemToggle itemWithItems:[NSArray arrayWithObjects:soundButtonOn,soundButtonOff, nil] block:^(id sender) { [self stopSounds]; }]; Anyone know a way to do this on SpriteKit? 回答1: Basic Toggle Button Subclassing a SKLabelNode .h typedef NS_ENUM