skshapenode

Drawing dashed line in Sprite Kit using SKShapeNode and CGPath

假装没事ソ 提交于 2019-12-06 03:28:18
问题 I want to draw a dashed line in my sprite kit game, I can use SKShapeNode node to draw a normal line like the following: UIBezierPath *_path=[UIBezierPath bezierPath]; //1 CGPoint point1 = CGPointMake(100,100); CGPoint point2 = CGPointMake(150,150); [_path moveToPoint:point1]; [_path addLineToPoint:point2]; //2 SKShapeNode *line = [SKShapeNode node]; line.path = _path.CGPath; I tried to set a dashed pattern to UIBezierPath like this: // adding this code at location 1 or 2 above but no effect

SKShapeNode filltexture() does not display image

心已入冬 提交于 2019-12-05 08:23:15
I want to create a circle that whose content is an image (.png), and based on the SKShapeNode class reference, I thought that I could use SKShapeNode.filltexture() function to set the texture to the image. But when i run the code below, I get the circle, but the image of the "cat-black" I am trying to load doesn't show. I checked that my Image.Assets have the image with the correct name, so something else is up. Any ideas? I attached the output below: func newCircle(photo:String, position:CGPoint) -> SKShapeNode { let circle = SKShapeNode.init(circleOfRadius: 27) circle.fillTexture = SKTexture

Confusion about coordinates, frames & child nodes in SpriteKit on iOS?

依然范特西╮ 提交于 2019-12-05 04:22:30
I'm still playing around with learning SpriteKit in iOS & have been doing lots of reading & lots of experimenting. I'm confused by something else I've found* regarding coordinates, frames & child nodes. Consider this snippet of code, in which I'm trying to draw a green box around my spaceship sprite for debugging purposes: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) let debugFrame = SKShapeNode(rect: spaceship.frame)

Sprite Kit - SKShapeNode Path not drawing Quad Curve

被刻印的时光 ゝ 提交于 2019-12-04 16:12:00
问题 I have been delving in to Apple's new Sprite Kit, and been using it for a while now. However I ran into an issue when trying to draw a curved path for an SKShapeNode . It just appears to draw a straight line instead. Here is a very simple example of the issue I am having - experimenting with drawing a CGPath for an SKShapeNode : CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0); CGPathAddLineToPoint(path,

Resizing a SKShapeNode

為{幸葍}努か 提交于 2019-12-04 13:03:00
How do I resize a SKShapeNode? What I've tried so far: Frame resize box.frame.width = 10 Gives the error Cannot assign to the result of this expression SKAction let actionResize = SKAction.resizeToWidth(10, duration: NSTimeInterval(0.1)) box.runAction(actionResize) Nothing happens xScale box.xScale = 0.1 Scales the node instead of resizing The action, resizeToWidth , can be called by an SKSpriteNode. You can call the action, scaleTo , with SKShapeNode. Change it to a var: var shapeNodeName = SKShapeNode(rectOfSize: CGSizeMake(100,100)) // change to new size - shape will now be 150 x 150

Rotating an SKShapeNode along its center

一个人想着一个人 提交于 2019-12-04 10:04:29
I have an SKShapeNode (rectangle in this case) which I am trying to rotate along its center. However it is rotating along the screen's bottom left point. Since I cannot set an anchor point for SKShapeNode, how can I achieve my requirement (to rotate the shape along its centre). This is the code I'm trying. let rectangle = SKShapeNode() rectangle.path = UIBezierPath(rect: CGRectMake(view.frame.width/4, view.frame.height/2, view.frame.width/2, view.frame.width/2)).CGPath rectangle.fillColor = UIColor.yellowColor() rectangle.strokeColor = UIColor.yellowColor() let oneRevolution = SKAction

Changing the image of a SKSprite to an SKShapeNode

梦想的初衷 提交于 2019-12-04 05:33:57
问题 Sprite Kit, Xcode. I need to find a way to change a sprites image within the program itself. I know how to create jpg files and make them into the sprite image... But for this program, I need to draw circles/polygons (which may change inside the program) using SKShapeNode, and then transferring this to the SKSpriteNode's image. Let's say I have declared: SKSpriteNode *sprite; SKShapeNode *image; How would I do this with these variables? Thanks! EDIT: I mean texture when I say image. 回答1: If I

Sprite Kit - SKShapeNode Path not drawing Quad Curve

余生颓废 提交于 2019-12-03 09:24:58
I have been delving in to Apple's new Sprite Kit, and been using it for a while now. However I ran into an issue when trying to draw a curved path for an SKShapeNode . It just appears to draw a straight line instead. Here is a very simple example of the issue I am having - experimenting with drawing a CGPath for an SKShapeNode : CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0); CGPathAddLineToPoint(path, NULL, 50, -100); CGPathCloseSubpath(path); SKShapeNode *shape = [[SKShapeNode alloc]init]; shape.path

SKSpriteNode frame way off

让人想犯罪 __ 提交于 2019-12-02 11:04:40
问题 I am trying to create an open circle from a UIBezierPath and turn that into an SKShapeNode which will later be turned into a SKSpriteNode. I had an problem where I could not figure out how to shrink a Sprite while its line width did not scale down. You can see the solution here: Resize sprite without shrinking contents I ended up fixing some things and creating a new class to implement a custom SKShapeNode with this functionality: class ShrinkableShape: SKShapeNode { let level: Int let

Changing the image of a SKSprite to an SKShapeNode

大城市里の小女人 提交于 2019-12-02 05:55:25
Sprite Kit, Xcode. I need to find a way to change a sprites image within the program itself. I know how to create jpg files and make them into the sprite image... But for this program, I need to draw circles/polygons (which may change inside the program) using SKShapeNode, and then transferring this to the SKSpriteNode's image. Let's say I have declared: SKSpriteNode *sprite; SKShapeNode *image; How would I do this with these variables? Thanks! EDIT: I mean texture when I say image. If I understand your question correctly, you can achieve what you're after using the textureFromNode method on