skspritenode

Resize sprite without shrinking contents

送分小仙女□ 提交于 2019-12-20 04:22:10
问题 I have created a big circle with a UIBezierPath and turned it into a Sprite using this, let path = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: CGFloat(226), startAngle: 0.0, endAngle: CGFloat(M_PI * 2), clockwise: false) // create a shape from the path and customize it let shape = SKShapeNode(path: path.cgPath) shape.lineWidth = 20 shape.position = center shape.strokeColor = UIColor(red:0.98, green:0.99, blue:0.99, alpha:1.00) let trackViewTexture = self.view!.texture(from: shape,

Moving an object across the screen at a certain speed.(Sprite Kit)

不问归期 提交于 2019-12-20 03:56:15
问题 I have an object that needs to move up and down the screen. When you first click it moves down the screen to an endpoint with a duration of 3 seconds. You can click at anytime to stop it from moving down and make it start moving up to a different endpoint, again at a duration of 3 seconds. The problem with doing it this way is if you click to move the object down but then immediately click again to move it up, the object moves up but at a very slow rate because it has a duration of 3 seconds.

iOS SKSpriteNode - Leave screen

纵然是瞬间 提交于 2019-12-20 03:32:23
问题 Is there any way to remove from Parent a SKSpriteNode that has left area bounds? for instance: -(void)didBeginContact:(SKPhysicsContact *)contact { firstNode = (SKSpriteNode *)contact.bodyA.node; if (firstNode.position.y<0) { [firstNode removeFromParent]; } } Just point me in the right direction. Is it the update method enumerate through checking their rects or is their an action you can apply. I have gone through the documentation can't seem to find it but I would have thought it would be an

How to compare SKSpriteNode textures

寵の児 提交于 2019-12-20 02:42:28
问题 I am making a game with Sprite Kit. When there is a collision I would like to retrieve the image of the SKSpriteNode that my projectile collided with to assign different point values depending on the image of the monster. I think comparing the texture property of the SKSpriteNode could work. I have tried the following code, but my if statement is never called. Any suggestions? - (void)projectile:(SKSpriteNode *)projectile didCollideWithMonster:(SKSpriteNode *)monster { SKTexture *tex =

How to get SKSpriteNode by physicsBody?

梦想与她 提交于 2019-12-19 11:35:44
问题 I extended SKSpriteNode with my own class to have more functions. But how can I get this extended node when something 'hits' this node and didBeginContact is called? Because contact.bodyA and contact.bodyB are physicsBody and parent of this is the game scene. This is my subclass of SKSpriteNode: class Orange: SKSpriteNode { ... func createPhysicsBody(){ self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2) self.physicsBody?.dynamic = true ... } } This is my didBeginContact

Animate an SKSpriteNode with textures that have a size different from the original

牧云@^-^@ 提交于 2019-12-19 10:56:11
问题 I want to animate an SKSpriteNode using textures from an SKTextureAtlas, using SKAction.animateWithTextures(textures,timePerFrame,resize,restore) . However, the textures in the atlas have a size that is slightly larger than the original texture (it's basically a character moving). When the action is run, the textures are either compressed to fit the original size of the sprite, or recentered when I set resize to false , which changes the position of the character. What I want, though, is for

Add SKReferenceNode/SKScene to another SKScene in SpriteKit

筅森魡賤 提交于 2019-12-18 05:12:15
问题 I would like to add a SKScene to my main GameScene. SKReferenceNode seems to be a good solution. I have : - GameScene.sks (main scene) - Countdown.sks (scene to add to GameScene) - Countdown.swift (Custom class, how does to init it? SKScene ? SKReferenceNode ? SKNode) I don't know how to add programmatically my countdown using my class Countdown. I tried: let path = Bundle.main.path(forResource: "Countdown", ofType: "sks") let cd = SKReferenceNode (url: NSURL (fileURLWithPath: path!) as URL)

Rotate an object in its direction of motion

﹥>﹥吖頭↗ 提交于 2019-12-18 04:27:28
问题 Is there a relatively simple way to rotate SKSpriteNode so that it is always facing the direction it is moving? My class Gamescene has a system of objects with their relative physicsbodies that apply impulses on each other when they collide. This makes it relatively difficult to keep track of exactly what direction an object is moving in. Some of the objects are also not regularly shaped, which makes things a bit more chaotic. I have tried using trigonometry (e.g. arctangent), but it only

SpriteKit SKPhysicsBody with Inner Edges

和自甴很熟 提交于 2019-12-14 04:17:52
问题 I have created an SKSpriteNode called let's say Map that has an edge path that I have defined (some simple polygon shape). What I am trying to figure out is how to add several other edge paths that would act as interior edges of the Map . As if the "map" as a whole did in fact have holes . Some sort of inner boundary shapes that could act with Map as a whole: one edge path (as shown below) © I understand that there is a method that allows for creating an SKPhysicsBody with bodies (some

Swift : Animate SKSpriteNode Gradient

守給你的承諾、 提交于 2019-12-14 03:21:12
问题 What i want to do seems very simple to me, but I can't figure out a way to implement it given that I am pretty new to iOS. I want to pretty much have my background a gradient that changes colors by fading in and fading out very slowly. I found this on github and used it to create two gradient nodes with different colors, the only issue is that I can't seem to animate its alpha or have it fade in and out in any way. https://github.com/braindrizzlestudio/BDGradientNode Here is what I did: /