sprite-kit

Turning Object with SkSpriteNode

╄→гoц情女王★ 提交于 2020-01-24 20:43:11
问题 I have an image named "Ghost" and it moves throughout the screen. I want to have the SpriteNode constantly turning without being pressed on. Ghost = SKSpriteNode(imageNamed: "Ghost1") Ghost.size = CGSize(width: 50, height: 50) Ghost.position = CGPoint(x: self.frame.width / 2 - Ghost.frame.width, y: self.frame.height / 2) Ghost.physicsBody = SKPhysicsBody(circleOfRadius: Ghost.frame.height / 1.4) Ghost.physicsBody?.categoryBitMask = PhysicsCatagory.Ghost Ghost.physicsBody?.collisionBitMask =

In objective C, when presenting a new scene, how do you remove the old scene?

余生颓废 提交于 2020-01-24 10:13:20
问题 I am new to Objective-C, so I may be using the wrong methodology to present the scene in the first place, but at the moment when I present my new scene, the old scene can be seen through it. - (void)buttonClicked:(UIButton*)button { NSLog(@"Button %ld clicked.", (long int)[button tag]); WarScene *battle = [[WarScene alloc] initWithSize: CGSizeMake(1024,768)]; SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:1.0]; SKView * skView = (SKView *)self.view

In objective C, when presenting a new scene, how do you remove the old scene?

﹥>﹥吖頭↗ 提交于 2020-01-24 10:13:08
问题 I am new to Objective-C, so I may be using the wrong methodology to present the scene in the first place, but at the moment when I present my new scene, the old scene can be seen through it. - (void)buttonClicked:(UIButton*)button { NSLog(@"Button %ld clicked.", (long int)[button tag]); WarScene *battle = [[WarScene alloc] initWithSize: CGSizeMake(1024,768)]; SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:1.0]; SKView * skView = (SKView *)self.view

OpenGL ES deprecated in iOS 12 and SKShader

落爺英雄遲暮 提交于 2020-01-24 08:52:09
问题 I am very new to the concept and use of shaders in SpriteKit. I found this tutorial on how to render a Mandelbrot fractal with a custom shader file - Fractal.fsh - attached to a Color Sprite's Custom Shader property. https://www.weheartswift.com/fractals-Xcode-6/ It works fine and I thought to my self that learning about OpenGL ES and custom shaders in SpriteKit would be a fun exercise. According to Apple though, OpenGL ES is deprecated as of iOS 12. https://developer.apple.com/library

bodyWithEdgeLoopFromRect not working in landscape

徘徊边缘 提交于 2020-01-24 06:03:46
问题 I'm just trying to set up a basic scene in landscape, with gravity, and having the scene in an edge loop. I set up the scene's physics body and the mainCharacter sprite physics body, here is my code: -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor redColor]; [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]]; } return self; } -(void)setupMain { if (!self.mainCharacter) { self.mainCharacter = [[SKSpriteNode alloc

bodyWithEdgeLoopFromRect not working in landscape

半城伤御伤魂 提交于 2020-01-24 06:03:32
问题 I'm just trying to set up a basic scene in landscape, with gravity, and having the scene in an edge loop. I set up the scene's physics body and the mainCharacter sprite physics body, here is my code: -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor redColor]; [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]]; } return self; } -(void)setupMain { if (!self.mainCharacter) { self.mainCharacter = [[SKSpriteNode alloc

Swift Compiler Error Int is not convertible to CGFloat

耗尽温柔 提交于 2020-01-24 04:31:46
问题 Im trying to run this code but the compiler is bugging me about Int can not convert to CGFloat, but I have never declare min, max or value as variables 'Int' nor mentioned them before. override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { /* Called when a touch begins */ bird.physicsBody.velocity = CGVectorMake(0, 0) bird.physicsBody.applyImpulse(CGVectorMake(0, 8)) } func clamp (min: CGFloat, max: CGFloat, value:CGFloat) -> CGFloat { if (value > max) { return max } else if

Passing integer between scenes, iphone game sprite-kit

蓝咒 提交于 2020-01-24 00:57:16
问题 I have a scene where the user chooses level in a game, then i want to switch to a game scene with the level the user chose. I want to create the game scene with the right level but to do this i need to pass an integer which is the level-number to the game scene so i know which level to load. My question is, how do i accomplish this? I have looked at the userdata property of nodes but could not figure out how to use it to accomplish what i want. Any help would be deeply appreciated. 回答1: When

SpriteKit Incorrectly Detecting Multiple Collisions

血红的双手。 提交于 2020-01-23 17:10:39
问题 I have been going through a SpriteKit tutorial that makes a Flappy Bird Style Game. One of the issues I am having, is that it is firing off the code for collision detection incorrectly. Sometimes, this goes perfect...it hits the ground, it fires the method for when it collides with the ground. However, at seemingly random times, it will hit the ground, and fire off the method for ground collisions anywhere from 2-6 times. It doesn't matter if any other nodes are present on the screen or not.

SpriteKit Incorrectly Detecting Multiple Collisions

浪尽此生 提交于 2020-01-23 17:10:10
问题 I have been going through a SpriteKit tutorial that makes a Flappy Bird Style Game. One of the issues I am having, is that it is firing off the code for collision detection incorrectly. Sometimes, this goes perfect...it hits the ground, it fires the method for when it collides with the ground. However, at seemingly random times, it will hit the ground, and fire off the method for ground collisions anywhere from 2-6 times. It doesn't matter if any other nodes are present on the screen or not.