sprite-kit

control max speed in sprite kit

时间秒杀一切 提交于 2020-01-04 02:46:12
问题 I'm trying to control the max speed of my character in my game. When I move him I use this: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint positionInScene = [touch locationInNode:self]; SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:positionInScene]; CGPoint posicionHero = [self childNodeWithName:@"hero"].position; SKSpriteNode *touchHero = (SKSpriteNode *)[self nodeAtPoint:posicionHero]; if((touchedNode !

Change a SKPhysicsBody's body shape

為{幸葍}努か 提交于 2020-01-03 21:08:45
问题 I don't want to change ANYTHING other than the body that defines the shape of a SKPhysicsBody. How do I do this? I can't seem to find where I can change this. Or even commentary on how to change it. Yes, I know this has to be done carefully, so that it avoids all possible new collisions, overlaps, etc. But putting that aside, how do I change the body of an SKPhysicsBody? 回答1: You can manually create a custom shape for a physics body using CGMutablePath , then pass it into the SKPhysicsBody

How to create custom SKActions?

时光怂恿深爱的人放手 提交于 2020-01-03 18:53:06
问题 Hello all I want to do is create a SKAction which does something similar to wheelRight.physicsBody.velocity = CGVectorMake(0, 1000); to a physics object. 回答1: Use SKAction runBlock: method: SKAction *changeVelocity = [SKAction runBlock:^{ wheelRight.physicsBody.velocity = CGVectorMake(0, 1000); }]; SKAction sequence = [SKAction sequence:@[..., changeVelocity, ..., ...]]; [wheelRight runAction:sequence]; 来源: https://stackoverflow.com/questions/21400928/how-to-create-custom-skactions

How to create custom SKActions?

吃可爱长大的小学妹 提交于 2020-01-03 18:53:05
问题 Hello all I want to do is create a SKAction which does something similar to wheelRight.physicsBody.velocity = CGVectorMake(0, 1000); to a physics object. 回答1: Use SKAction runBlock: method: SKAction *changeVelocity = [SKAction runBlock:^{ wheelRight.physicsBody.velocity = CGVectorMake(0, 1000); }]; SKAction sequence = [SKAction sequence:@[..., changeVelocity, ..., ...]]; [wheelRight runAction:sequence]; 来源: https://stackoverflow.com/questions/21400928/how-to-create-custom-skactions

How to switch SKScenes in SpriteKit with Swift properly?

安稳与你 提交于 2020-01-03 17:21:09
问题 I am developing a game with 3 different SKScenes(scene1, scene2, scene3). In GameViewController i initialize all of them like this: class GameViewController: UIViewController { var hero = Hero() var skView: SKView! var scene1: SKScene! var scene2: SKScene! var scene3: SKScene! override func viewDidLoad() { super.viewDidLoad() // init scenes scene1 = SKScene(size: view.bounds.size, hero: hero) scene2 = SKScene(size: view.bounds.size, hero: hero) scene3 = SKScene(size: view.bounds.size, hero:

SpriteKit & Swift: Creating nodes via didBeginContact messes up the positioning

萝らか妹 提交于 2020-01-03 17:10:30
问题 I don't know if this is a weird bug in Xcode or there's something about the SpriteKit's coordinate system I don't understand. The premise is that the position of a node is always relative to its parent. However, whenever I call a block that creates and positions a node with a physics body from "didBeginContact" of SKPhysicsContactDelegate, the node is always positioned relative to the scene (instead of its parent). Note that calling this same block works as intended when triggered anywhere

SpriteKit & Swift: Creating nodes via didBeginContact messes up the positioning

╄→尐↘猪︶ㄣ 提交于 2020-01-03 17:10:09
问题 I don't know if this is a weird bug in Xcode or there's something about the SpriteKit's coordinate system I don't understand. The premise is that the position of a node is always relative to its parent. However, whenever I call a block that creates and positions a node with a physics body from "didBeginContact" of SKPhysicsContactDelegate, the node is always positioned relative to the scene (instead of its parent). Note that calling this same block works as intended when triggered anywhere

Swift: How to make my character in my game only be able to jump once he hits the ground?

你说的曾经没有我的故事 提交于 2020-01-03 17:07:53
问题 I'm developing a game where my character jumps from land to land. I have everything down and done except my remaining problem is if you keep tapping the screen he can keep jumping forever. I want it so he has to hit the ground before he can jump again. import SpriteKit import GameplayKit class GameScene: SKScene, SKPhysicsContactDelegate { struct PhysicsCatagory { static let Knight : UInt32 = 0x1 << 1 static let land : UInt32 = 0x1 << 2 } var Knight = SKSpriteNode() var land = SKSpriteNode

How to calculate the similarity of two line drawing images in swift

房东的猫 提交于 2020-01-03 08:24:09
问题 We need to compare two hand drawn images..these images are drawn on the sprite kit.we need to see whether these pictures are roughly match or not. For Example, if someone draws a smile pic, we need to check whether the redrawing smile pic is looks like the first drawn smile pic or not.we need to know whether the two images look alike or not...and to calculate the accuracy percentage of how similar they are..Please suggest some solutions.Thanks in advance. 回答1: You could try draw each of the

Alternative to UISwipeGestureRecognizer?

坚强是说给别人听的谎言 提交于 2020-01-03 04:47:08
问题 I have 3 SKScenes in SpriteKit, Swift: Level 1 Game Over Level 2. In Level 1 and Level 2, my character movement is done by the following code: class Level1: SKScene, SKPhysicsContactDelegate { func swipedRight(sender:UISwipeGestureRecognizer){ let moveRIGHT = SKAction.moveBy(CGVectorMake(60, 0), duration: 1) Character.runAction(moveRIGHT) } func swipedLeft(sender:UISwipeGestureRecognizer){ let moveLEFT = SKAction.moveBy(CGVectorMake(-60, 0), duration: 1) Character.runAction(moveLEFT) } let