skspritenode

Build a grid level for a game with SpriteKit and SWIFT

本秂侑毒 提交于 2019-12-24 16:13:06
问题 I’m searching the best way to build the levels for a game : The game will be composed with many levels, each levels will be unique. You’ll play an object (here the star), which is in movement on a grid. The object can move only to the bottom, it cannot go back. A level is composed with many cases, each cases will have a different behavior. My level will have a background, width of the screen, but the height will depend on the level, I suppose many times the height of the screen. The

SKPhysicsBody from Texture gives null on collision in Spritekit

别来无恙 提交于 2019-12-24 07:39:35
问题 I am creating a game where character jumps and collect points (SOME OBJECT). When you tap character perform some animation from atlas. When it touches the points, score is increased by 1. I am using SKTexture to create physicbody of the character. When my character touches the point it crashes and show me this error fatal error: unexpectedly found nil while unwrapping an Optional value //Code Cat = SKSpriteNode(imageNamed: "cat"); Cat.size = CGSize(width: 100, height: 100) Cat.position =

Swift 1.2 bug: different behavior between iOS 7.1 and 8.3 while removing SKSpriteNode from parent

China☆狼群 提交于 2019-12-24 04:04:35
问题 Sample project: https://github.com/wilkinho/RemoveFromParentTest Swift version: 1.2 Xcode version: 6.3 I try to remove a SKSpriteNode from its parent and add it back to the SKScene within its own SKAction run block (or callback). The result differs in iOS 7.1 and 8.3. In iOS 7.1, after touching the device, the console prints: sprite.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}}) sprite.scene:nil sprite2.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})

Create a subclass of a SKSpriteNode subclass

吃可爱长大的小学妹 提交于 2019-12-24 01:14:53
问题 Let's say I want to create a bunch of different types of Spaceships. I want to setup a base spaceship class that I can use to create other spaceships with minor differences. My base class looks like this. // BaseSpaceship.h @interface SpaceshipNode : SKSpriteNode @property NSColor color; @property CGFloat engineThrust; + (id)baseSpaceshipWithImageNamed:(NSString *)name; @end // BaseSpaceship.m @implementation BaseSpaceship + (id)baseSpaceshipWithImageNamed:(NSString *)name { BaseSpaceship

How to create CGPath from a SKSpriteNode in SWIFT

爷,独闯天下 提交于 2019-12-24 00:52:05
问题 I have a SKSpriteNode create with the level generator. I need to create exactly the same shape using CGPath. self.firstSquare = childNodeWithName("square") as! SKSpriteNode var transform = CGAffineTransformMakeRotation(self.firstSquare.zRotation) let rect = CGRect(origin: self.firstSquare.position, size: self.firstSquare.size) let firstSquareCGPath:CGPath=CGPathCreateWithRect(rect, &transform) print(self.firstSquare.position) => firstSquare position (52.8359451293945, -52.9375076293945) To

How do I move a SKSpriteNode up and down around its starting value in Swift?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 16:53:43
问题 I'm currently working on a game, where there's a SKSpriteNode. I want, that this node's location moves up and down all the time. At the beginning, it should have the y value e.g. 500 . Then it should move 200 px down (500+200=700) and then it should move 400 up (700-400=300) so it creates like a up and down, which travels between 500+200 and 500-200 all the time. I hope I explained it understandable. First, how do I get this effect and second, where do I enter it? Should I use a custom func?

Why is the coordinate system in sprite kit flipped and can I change that globally?

雨燕双飞 提交于 2019-12-23 08:57:57
问题 I noticed that in Sprite Kit the coordinate system is flipped. For example, here is a SKSpriteNode: SKSpriteNode *car = [SKSpriteNode spriteNodeWithImageNamed:@"car"]; car.position = CGPointMake(0, 0); [road addChild:car]; The car is positioned in the center of it's parent. When I set position to: car.position = CGPointMake(-50, 0); then it is positioned more to the left. But when I want to move it down, and increase Y, it moves UP! car.position = CGPointMake(-50, 20); In UIKit increasing Y

drawing line using vertex shader & fragment shader in spritkit in swift

夙愿已清 提交于 2019-12-23 01:07:08
问题 I need to draw a line between two spritnodes while hand is pointing from one node to another with rendering or animation. The line drawing is working for me as I follow this link Bobjt's answer, Animate Path Drawing in SpriteKit . I have used concept of fragment shader and vertex shader here.. I have added animatestroke.fsh file and apply the following code .. But the handplayer animation and line drawing speed is mismatching some times. my line rendering i have given increment by

Why won't my SKSpriteNodes appear in the scene?

坚强是说给别人听的谎言 提交于 2019-12-23 01:03:28
问题 I am trying to add a couple of nodes to the scene. When I run the app I just have the default gray background. Neither of the nodes appear in the scene. Here is what I have: class GameScene: SKScene { override func didMoveToView(view: SKView) { /* Setup your scene here */ let jumper = SKSpriteNode(imageNamed:"Jumper") jumper.xScale = 0.25 jumper.yScale = 0.25 jumper.position = CGPointMake(50, 300) self.addChild(jumper) let blob = SKSpriteNode(imageNamed:"Blob") blob.position = CGPointMake(160

Create SKSpriteNode with an Asset Programmatically

ぃ、小莉子 提交于 2019-12-22 13:53:50
问题 I'm attempting to programmatically create an SKSpriteNode and give it a texture that is in my Assets.xcassets folder. I figured this would be a basic procedure, but I seem to be having a lot of troubles. For a reference, here is my asset catalog with the ground asset I'm trying to set to a SKSpriteNode : Here's the code to make the sprite node: sprite.texture = SKTexture(image: UIImage(named: spriteName)!) sprite.anchorPoint = CGPoint(x: 0, y: 1) sprite.position = CGPoint(x: 0, y: 0)