skshapenode

Detecting Touch on SKShapeNode that is a Line

天大地大妈咪最大 提交于 2019-12-13 07:39:12
问题 I have an SKShapeNode that I have created and given a CGPath to. This is in my GameScene.swift in didMoveToView: let myNode = SKShapeNode() let lineToDraw = CGPathCreateMutable() CGPathMoveToPoint(lineToDraw, nil, 0, 0) CGPathAddLineToPoint(lineToDraw, nil, 87, 120) myNode.path = lineToDraw myNode.strokeColor = SKColor.redColor() myNode.lineWidth = 20 myNode.name = "My Node!" world.addChild(myNode) // World is a higher-level node in my scene And this is how I'm detecting touches, again in the

Anchorpoint on SKShapeNode or something else

佐手、 提交于 2019-12-13 04:23:12
问题 I can't figure out how to make the anchorpoint in my SKShapeNode that is probably set to (0.5,0.0) to (0,0) since when my game draws the path the coordinate system is not working right... Thanks for the help 回答1: SKShapeNode does not have an anchorPoint. LearnCocos2D answered on this issue: When you use an image you may need to align it on its node's position. There's no other way to do so but through anchorPoint because the image itself can't be modified (not easily anyway). When you create

skshapenode adding two nodes?

霸气de小男生 提交于 2019-12-12 00:25:24
问题 I'm not sure whether there's an issue with the implementation or the way I'm using it. However, it's presenting over 2,400 nodes when it should be ~ 1,250 -(void)drawWeb { //get distance of 50 across int distanceMargin = _background.frame.size.width/50; NSLog(@"%i", distanceMargin); __block int xCounter = distanceMargin; __block int yCounter = 0; NSArray *alphabet = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",

Drawing line with Touch iOS Sprite Kit

为君一笑 提交于 2019-12-11 21:10:00
问题 Im using the following code to draw lines in my sprite kit scene but nothing shows up. But the node counts goes up. Can anyone see what could be the problem. Ive been fighting with this code forever - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; CGPoint positionInScene = [touch locationInNode:self]; pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y); lineNode = [SKShapeNode

How can you detect if SKShapeNode is touched?

旧城冷巷雨未停 提交于 2019-12-08 06:13:07
问题 I created a sknodeshape. How can I detect if the shape I made was touched(clicked)? Here is the code: (I solved it already) //metung_babi is the name of the SKShapeNode UITouch *touch = [touches anyObject]; CGPoint nokarin = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:nokarin]; if ([node.name isEqualToString:@"metung_babi"]) { NSlog(@"touch me not"); } my mistake was when I created the shape I put the SKShapeNode name before initializing it. 回答1: Implement the touch delegate

Making SKLabelNode as a crop node of SKShapeNode

对着背影说爱祢 提交于 2019-12-08 00:12:14
问题 Can't find in web, how to make SKLabelNode cropping SKShapeNode. When i colorize the background, my goal is colorize the label too with the same method, so both of them have to colorize simultaneously. But can't imagine how to crop SKShapeNode with this label. Help me please! 回答1: But can't imagine how to crop SKShapeNode with this label. If I understand you correctly, you can set SKLabelNode as a mask of a SKCropNode, like this: override func didMoveToView(view: SKView) { backgroundColor =

SKshapenode is not responding to Physicsbody

社会主义新天地 提交于 2019-12-07 22:55:28
问题 I have created a SKShapeNode and I have assigned a physicsBody to it. However, it is not being triggered when there is contact. Creation of SKShapeNode code: -(SKShapeNode*)gravityline{ //SKSpriteNode *lolo=[[SKSpriteNode alloc]init]; SKShapeNode *lolo = [[SKShapeNode alloc] init]; CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, fff.x, fff.y); CGPathAddLineToPoint(path, 0,rayoriginpoint.x,rayoriginpoint.y

Assigning an image to a SKShapeNode as a Ball - Spritekit Game

让人想犯罪 __ 提交于 2019-12-07 19:37:43
问题 I am trying to add an image to my ball in my Swift 2 Sprite-kit game. I have a make() ball function and it there are no errors there however in the game scene, when the method is called, I keep receiving this error : "Cannot assign SKShapeNode' to type Ball! I am not sure how to fix and am new to Swift. // ----- GameScene.Swift ---- class GameScene: SKScene, GameDelegate, SKPhysicsContactDelegate { // ball part one var ball: Ball! let ballSpeedX = CGFloat(500) } override func didMoveToView

SKshapenode is not responding to Physicsbody

风流意气都作罢 提交于 2019-12-06 13:44:30
I have created a SKShapeNode and I have assigned a physicsBody to it. However, it is not being triggered when there is contact. Creation of SKShapeNode code: -(SKShapeNode*)gravityline{ //SKSpriteNode *lolo=[[SKSpriteNode alloc]init]; SKShapeNode *lolo = [[SKShapeNode alloc] init]; CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, fff.x, fff.y); CGPathAddLineToPoint(path, 0,rayoriginpoint.x,rayoriginpoint.y ); CGPathCloseSubpath(path); lolo.path = path; lolo.name=@"gravityline"; lolo.strokeColor=[SKColor

Resizing a SKShapeNode

我怕爱的太早我们不能终老 提交于 2019-12-06 08:25:31
问题 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 回答1: The action, resizeToWidth , can be called by an SKSpriteNode. You can call the action, scaleTo , with SKShapeNode. 回答2: Change it to a var: var