As suggested by iAnum I got answer from that post and here is my code: This way I add 2 backgrounds. func addScrollingBG() { bg1 = SKSpriteNode(imageNamed: "bgPlayScene") bg1.anchorPoint = CGPointZero bg1.position = CGPointMake(0, 0) bg1.size = CGSize(width: frame.size.width, height: frame.size.height) addChild(bg1) bg2 = SKSpriteNode(imageNamed: "bgPlayScene") bg2.anchorPoint = CGPointZero bg2.position...
swift,colors,sprite-kit,blend,skspritenode
How about something like this: func blendColor(color1: UIColor, withColor color2: UIColor) -> UIColor { var (r1:CGFloat, g1:CGFloat, b1:CGFloat, a1:CGFloat) = (0, 0, 0, 0) var (r2:CGFloat, g2:CGFloat, b2:CGFloat, a2:CGFloat) = (0, 0, 0, 0) color1.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) color2.getRed(&r2, green: &g2, blue: &b2, alpha: &a2) return UIColor(red:...
The name of the sprite has no real bearing on identification in regards to movement. You can either make one sprite the parent and attach all other sprites as children. Doing this will make all children move when you move the parent or you can dump all the sprites into...
sprite-kit,collision-detection,skspritenode
Changing the sprite's anchor point have no effect on the physics body. When talking about CGRect, the rect origin is at point {0, 0}, So what is happening is that you now have a sprite that its image is centred around anchor point {0, 0} but with a physics body,...
ios,objective-c,sprite-kit,skspritenode
The short answer is no. You already have a UIView which you can access in the view from didMoveToView:(SKView *)view. All nodes reside in that view. If you add another view, it either goes in front or behind the 'SKView'. ...
ios,animation,rotation,sprite-kit,skspritenode
In your didSimulatePhysics or your update you can rotate your sprite towards its vector. Not sure theres a way to automatically make this happen. let angle = atan2(mySprite.physicsBody!.velocity.dy, mySprite.physicsBody!.velocity.dx) mySprite.zRotation = angle ...
ios,ios8,sprite-kit,2d-games,skspritenode
Just an idea: Can't you use two Sprites for the building which are positioned at the same place: - one represents the physics body of your building (the left one from your image) - invert your collision map image to get a single physics body block. The special areas should...
ios,swift,sprite-kit,skspritenode
One of the simplest ways to achieve this would be to use this (no need to implement touchesBegan): override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { for touch in (touches as! Set<UITouch>) { let location = touch.locationInNode(self) for childNode in children { if (childNode is SKSpriteNode) { let node =...
You have a couple of options: 1) You could rotate the centerNode over time in your SKScene's update: method by changing its zRotation property manually. You'll have to change the value slowly, at every call to update: to achieve a gradual rotation. Note that the zRotation property is in radians,...
swift,sprite-kit,skspritenode,touchesbegan
You can remove a particular node in the following way. First set the node.name property at the place where you add it. func generateNode() { // your node creation code node.name = "generatedNode" //add your node. } Then in touchesBegan, you can remove the touched node if the name of...
ios,sprite-kit,progress-bar,skspritenode,skcropnode
Although you appear to have found a solution in Sanders answer, I would advise using SKScene's update: method, which is part of the SpriteKit rendering loop. Adding your own asynchronous calls will eventually bite you in the behind. The update: method is called once every frame and should be more...
ios,objective-c,sprite-kit,nskeyedarchiver,skspritenode
Following up on my own question, what I opted to do instead was to store game state in [NSUserDefaults standardUserDefaults] and [NSUbiquitousKeyValueStore defaultStore] for iCloud. I now save NSMutableArrays of NSMutableDictionarys representing my card attributes in user defaults, and then i rebuild my sprites from these values when it comes...
SKAction.moveToY accept a CGFloat for Y and an NSTimeInterval for duration. Therefore you need to change position's type to [CGFloat] and speed's type to [NSTimeInterval]. There are a few other things I notice with your code: 1. I think it's a typo - you've written let moveRight1 = SKAction.moveToY in...
The speed property of SKNode is to do with SKActions, however the speed property of SKPhysicsWorld is what you probably want to tweak to achieve physics in slow motion. It says the following in the documentation about the speed property of SKPhysicsWorld The default value is 1.0, which means the...
ios,sprite-kit,skspritenode,skphysicsbody,skphysicsjoint
this is my working code.... CGPoint position = CGPointMake(100, 350); CGPoint position2 = CGPointMake(100, 420); CGSize size = CGSizeMake(4, 164); SKSpriteNode *node1 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size]; node1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size]; node1.position = position; SKSpriteNode *node2 = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:size]; node2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size]; node2.position = position2; [scene addChild:node1];...
You have declared the obstacles array as containing instances of obstacle, but you are trying to append an instance of its superclass, SKSpriteNode. Just change that to create an instance of obstacle instead: obstacles.append(obstacle(imageNamed: "Rectangle")) Remember that if you have a base class A and a subclass of it B...
objective-c,sprite-kit,skspritenode
There is. Internally, the spriteNodeWithImageNamed: class method just uses the image name you pass it to set the node's texture property. That being said, if at any point you want to arbitrarily change the node's texture, you can just set it directly. [self.sprite setTexture:[SKTexture textureWithImageNamed:@"someOtherImage"]]; There are also some SKActions...
objective-c,arrays,sprite-kit,skspritenode,sknode
I have written a card game in my spare time as well so I know the issue you are looking at. I created a subclass of SKSpriteNode and in it I had keys with the different values the cards had. However you don't even need to do that if you...
objective-c,sprite-kit,skspritenode,skaction
That method is another constructor method for SKAction. That is, all it does is create another action that you can run on a node. So you should have... SKAction *runOnChildAction = [SKAction runAction:action2 onChildWithName:@"SpriteMegamen"]; [self runAction:runOnChildAction]; Just a note. I found all this out purely by reading the documentation for...
ios,swift,sprite-kit,skspritenode
I noticed that the difference between creating a SKSpriteNode with texture and a SKSpriteNode with color is that the texture version doesn't need to have its z-index modified. It will display over the previous addChild(someNodes) automatically. They both have a default z-index of 0 but for some reasons SKSpriteNode with...
swift,random,sprite-kit,skspritenode,skaction
The function you are using is not valid. Use SKAction.moveTo instead. dino.position = CGPoint(x: size.width + dino.size.width/2, y: 10) // Add the monster to the scene addChild(dino) // Determine speed of the monster let actualDuration = NSTimeInterval(random(min: CGFloat(3.0), max: CGFloat(4.0))) let randomNum = CGPoint(x:Int (arc4random() % 1000), y:Int (arc4random() %...
ios,sprite-kit,skspritenode,skphysicsbody,skphysicsworld
If you apply an impulse to a node's physics body it is only applied once. Think of kicking a ball. Applying a force on the other hand is like a continuos push, like an engine moving a car. Keep in mind that if you continue to apply force, your node...
ios,swift,sprite-kit,skspritenode,skscene
I assume that GameScene has a child SKLabelNode named "scoreLabel" "scoreLabel" shows the current score of the game GameScene has a child SKSpriteNode named "mySprite" When "mySprite" receives a tap, the score must be increased by 1 GameScene has a private property var score = 0 This is how...
ios,swift,sprite-kit,skspritenode
Please check the answer for this question: multitouch in spritekit The idea is that you should track individual touches separately. ...
This code is working fine: import SpriteKit class GameScene: SKScene { let runner = SKSpriteNode(imageNamed: "Spaceship") override func didMoveToView(view: SKView) { self.createRunner() } override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { var touch = touches.first as! UITouch var touchLocation = touch.locationInNode(self) runner.position = touchLocation } override func touchesMoved(touches: Set<NSObject>, withEvent...
ios,swift,sprite-kit,skspritenode,skshapenode
You are creating the shape node using the sprite's frame, which is in scene coordinates. Because the shape will be a child of the sprite, you should create the node in the sprite's coordinates. For example, if you create the SKShapeNode with spaceship's size let debugFrame = SKShapeNode(rectOfSize: spaceship.size) instead...
swift,sprite-kit,skspritenode,sknode
You're nearly there, what you need to use is: let positionInScene = self.convertPoint(child.position, fromNode: platformGroupNode) // self in this case is your SKScene, you don't need self here but, IMO, it // makes it easier to understand what's converting what. Or an equivalent would be: let positionInScene = platformGroupNode.convertPoint(child.position, toNode:...
ios,objective-c,sprite-kit,game-physics,skspritenode
Since you are using physics you can use the resting property of SKPhysicsBody. if sprite.physicsBody?.resting == true { println("The sprite is resting") } else { println("The sprite is moving") } Hope this helps....
ios,objective-c,sprite-kit,collision-detection,skspritenode
Adjusting the mass can help in not deflecting the moving object. For example try this code, SKSpriteNode *fallNode = [[SKSpriteNode alloc] initWithColor:[UIColor redColor] size:CGSizeMake(25, 25)]; fallNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:fallNode.size]; fallNode.position = CGPointMake(100, 400); fallNode.physicsBody.mass = 1; fallNode.physicsBody.allowsRotation = NO; fallNode.physicsBody.restitution = 0.0; fallNode.physicsBody.friction = 1.0; [self addChild : fallNode]; SKSpriteNode...
ios,objective-c,sprite-kit,skspritenode
Remove the ball global variable, as it's not needed. Test all nodes for the specified name of @"ball" and return YES if none were found: -(BOOL)isGameWon { for (SKNode* node in self.children) if ([node.name isEqualToString:@"ball"]) return NO; return YES; } ...
ios,objective-c,sprite-kit,skspritenode,anchorpoint
First of all set anchor point: self.p_stick.anchorPoint = CGPointMake(0.5, 0); Also you can set dynamic property NO for all. You need to use this atan2f function (atan2f(SK_DEGREES_TO_RADIANS(90), SK_DEGREES_TO_RADIANS(0))) ...
ios,sprite-kit,skspritenode,touchesbegan
I made a mistake, it was not changing colors because I initialized the sprite with a texture as opposed to a color. I fixed it with the following code: mySKSpriteNode=[SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(50, 50)]; ...
sprite-kit,shadow,skspritenode,sklightnode
I just heard back from Apple Developer Technical Support confirming this is a bug in SpriteKit (SKLightNode). Currently they do not know of a workaround for this issue but will update me if one is found. As per their request, I have filed a bug report. UPDATE April 22, 2015...
ios,objective-c,sprite-kit,skspritenode
I would say the fact that you have them rendering and moving up you are off to a great start. My recommendation though would be to look at a MVC (Model View Controller) approach to the problem. Keep the info for cards played and what the player has for cards...
swift,sprite-kit,skspritenode,skaction
When you run actions like from your example and randomize duration parameter with something like arc4Random this is actually happening: Random duration is set and stored in action. Then action is reused in a sequence with a given duration. Because the action is reused as it is, duration parameter remains...
objective-c,sprite-kit,skspritenode
This problem can be solved with a little bit of math. A circle around the point (x0,y0) with the radius r can be written as x = x0 + r * sin(t) y = y0 + r * cos(t) with t going from 0 to 2π. If you plug in...
ios,objective-c,sprite-kit,skspritenode,skaction
Actually all of your nodes are moving together without delay to the same point. This is because you are not incrementing your i variable inside the loop. Try the code below. For the SKAction to work properly also set affectedByGravity to false. int i = 0; for (SKSpriteNode *shot in...
SKScene is a subclass of SKNode so you do in fact inherit it. You can use SKTexture to change the image like this: player.texture = SKTexture(imageNamed: "player1") ...
objective-c,sprite-kit,skspritenode,sktexture
It's all the same. If there are any performance differences they are probably minute. Still, if you already have a texture you can avoid the file/cache lookup costs by using the withTexture initializers.
ios,objective-c,ios7,sprite-kit,skspritenode
Apple docs say, "An SKScene object represents a scene of content in Sprite Kit. A scene is the root node in a tree of Sprite Kit nodes..." So, use the following statement in your SKScene class, see if it outputs the correct number. NSLog(@"%lu", (unsigned long)[self.children count]); ...
objective-c,ios8,sprite-kit,subclass,skspritenode
you can use the main update method, and put the update method in your NPC subclasses. Heres a loose example of how you keep track of time outside of your GameScene class NPC: SKSpriteNode { var delta = NSTimeInterval(0) // this update gets called from the GameScene class, // put...
ios,objective-c,image,sprite-kit,skspritenode
You can use the anchor point property of the background node to change the point from which image scales. By default the anchorPoint is at (0.5,0.5). This indicates the center of the node. If you make the anchorPoint (0,0), then its moved to the bottom left corner. anchorPoint : Defines...
ios,swift,sprite-kit,skspritenode
It's really a bad idea to use animation by calling methods that way. Here is a way to do the same thing with sequenced and repeated actions wrapping the basic commands: let move = SKAction.moveTo(CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)), duration: 0) let fire = SKAction.moveTo(CGPointMake(100.0, 100.0), duration: 0.25) let wait = SKAction.waitForDuration(0.5) let...
objective-c,sprite-kit,collision-detection,skspritenode
Ok so you've got the BitMasks set up so that's a start. To see whether something has had a contact: make sure that the scene has the <SKPhysicsContactDelegate> in front of interface use didBeginContact method to see if a collision has occurred set up bitMasks likewise: CategoryBitMask - identifies the...
sprite-kit,skspritenode,skaction
Found the problem. It was a logical issue. The SKSpriteNode was being added and the sound FX started playing, but in the next frame or so the sprite was being removed. As a result, it appeared that the sprite wasn't being displayed, but didn't have time to move into view....
sprite-kit,skspritenode,swift2,xcode7
in Swift 1.2 the initializer you are calling on super used to accept an implicitly-unwrapped optional for the color, hence you were able to pass nil in Swift 2, that same initializer no longer accepts an optional, you must pass a UIColor if you use it (see docs) your solution...
ios,objective-c,sprite-kit,skspritenode,skemitternode
You have these two nodes you are creating: MCBomb *_multiUp = [MCBomb spriteNodeWithImageNamed:@"MultiShotPowerUp"]; [_mainLayer addChild:_multiUp]; // Create spark. NSString *bombSparkPath = [[NSBundle mainBundle] pathForResource:@"BombSpark" ofType:@"sks"]; SKEmitterNode *_bombSpark = [NSKeyedUnarchiver unarchiveObjectWithFile:bombSparkPath]; _bombSpark.targetNode = _mainLayer; [_mainLayer addChild:_bombSpark]; but you are adding your spark to the mainLayer which is not correct for what...
ios,sprite-kit,velocity,skspritenode,skphysicsbody
Restitution basically equates to an object's "bounciness". Sprite Kit Physicsbody Restitution is defined as Property describing how much energy a body retains when it bounces off of another body, basically a fancy way of saying "bounciness"" -IOS Games by Tutorials* So make self.physicsBody.restitution = 1.0; Refer Restitution...
ios,objective-c,sprite-kit,skspritenode
You need to add your background image to the SKScene view and as such determine the coordinates from self. SKSpriteNode *backgroundNode = [SKSpriteNode spriteNodeWithImageNamed:@"BackgroundImage"]; backgroundNode.position = CGPointMake(self.size.width/2, self.size.height/2); backgroundNode.zPosition = 1; [self addChild:backgroundNode]; ...
swift,ios8,sprite-kit,skspritenode
You can set the SKTexture as your SKPhysicsbody parameter: randomMountain.physicsBody = SKPhysicsBody(texture: mountainTexture, size: mountainTexture.size) The ...
sprite-kit,removechild,skspritenode,sknode
http://stackoverflow.com/a/24195006/2494064 Here is a link to an answer that removes nodes that go off the top of the screen. You would just have to replicate this to cover the entire border and set all of the walls to have the same contactBitMask values. Basically the logic is to remove the...
Try this. func getDamage2Unit(val:AnyObject){ if let myType = val as? Unit1 { println("this AnyObject is Unit1 objects") } } Now if you know that val will be always of type Unit1, then change AnyObject to Unit1 or func getDamage2Unit(val:AnyObject) { let myType = val as Unit1? if myType != nil...
You are setting the name of the variable, but you are not setting the name of the SKSpriteNode. It should be: sprite1.name = @"sprite1"; Follow suit for the rest of your sprites. Another thing I noticed is that you call self.name. I am pretty sure self refers to the scene,...
I don't know exactly why it was causing an issue, but one of my sprites from the last scene was causing the crash. I removed it and now it works fine.
objective-c,sprite-kit,skspritenode
To access the first object in an array of sprites you can do this: SKSpriteNode *object = [myArray firstObject]; object.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height)); To access all objects in an array do this: for(SKSpriteNode *object in myArray) { object.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height)); } ...
sprite-kit,trigonometry,skspritenode,cgpoint
I solved it after trying some more and here's how i did it: - (CGVector)convertAngleToVector:(CGFloat)radians { CGVector vector; vector.dx = cos(radians) * 40; vector.dy = sin(radians) * 40; return vector; } I call the method with the sprites zRotation which gives me a vector. The number 40 decides how long...
ios,swift,sprite-kit,skspritenode,skscene
If you look at the definition of Class ArcheryScene you will see it is a subclass of SKScene - so the class you are coding in is already your scene. The UIViewController subclass in your project has loaded ArcheryScene.sks and associated it with an instance of ArcheryScene. When you subsequently...
ios,swift,sprite-kit,skspritenode
A few Options might be: 1. Save highscore in app delegate. I gameover scene print it from appDelegate. 2. Save highscore in NSUserDefault. then in GameOverScene show it form there. 3. Create a property in GameOverScene and while navigating to GameOverSecne from GameScene set that property. Here is some tutorial...
ios,swift,sprite-kit,skspritenode
To randomly select something arc4random and its friends are nice. My take for the CircleType: let ct = CircleType(rawValue: UInt(arc4random_uniform(3) + 1)) As described in http://nshipster.com/random/ arc4random_uniform(N) delivers a random int between 0 and N-1....
So, in order to show only half of the image, texture, sprite, someone would need to use a SKCropNode. The only sensible thing is to crop the sprite you need starting from half, not just cropping with a predefined size. This can be achieved by setting the mask node position....
swift,sprite-kit,skspritenode,touchesbegan
Note that in this case you need bidirectional relationships - your game objects need to access the nodes but also the nodes need to access their game objects. I don't think you can completely avoid inheritance in this case. The simplest method would be to inherit from SKSpriteNode and add...
swift,sprite-kit,skspritenode,sknode
The answer is simple. Set the node's anchorPoint to (0,0) (or any of the other 3 corners).
Use a sequence SKAction to queue a few actions together with the parameters you want. In your case, this might be a good start: var actions = [SKAction]() for var i = 5.0; i > 0; i -= 0.5 { actions.append(SKAction.rotateByAngle(CGFloat(2.0 * M_PI), duration:i)) } let sequence = SKAction.sequence(actions) sprite.runAction(sequence);...
ios,swift,sprite-kit,skspritenode
Solved it setting the SKEmitterNode´s targetnode property to another node other than the one im detecting taps on. https://developer.apple.com/library/mac/Documentation/SpriteKit/Reference/SKEmitterNode_Ref/index.html#//apple_ref/occ/instp/SKEmitterNode/targetNode emitter.targetNode = self.scene ...
objective-c,sprite-kit,skspritenode,sknode
Check out CIPerspectiveTransform filter.I believe it is possible to apply it using SKEffectNode.
The higher the nodes with physics bodies, the lower the framerate. The lower the framerate, the crazier the engine gets. One time I've even see it make some kind of blackhole. It'll help if you lessen the force against the wall, whether gravity, or velocity from applyforce. Also making sure...
ios,swift,sprite-kit,skspritenode,skphysicsbody
I was having an almost identical problem. I started with code from a Ray Wenderlich tutorial and started subclassing from there. Well, I'm pretty sure that the tutorial swaps the projectile and the monster in didBeginContact. Since they're the same class, and it just removes them both, it didn't matter....
ios,swift,sprite-kit,skspritenode
are you using the sks file to make your SKView? Or are you instantiating it in your viewcontroller? Important to get the dimensions for your scene correct. I know this isn't directly answering your question, but if you're getting weird stretching and stuff, maybe you should start with this and...
swift,sprite-kit,skspritenode,spawn,skaction
If I remember well, the waitForDuration:withRange: method works like so : if you put a duration of 3 (seconds) and a range of 1 seconds the random value that you get will be between 2 and 4 seconds. That said, you should use those value for what you described :...
swift,sprite-kit,skspritenode,skemitternode,sktransition
If I understand your question correctly, you could add the particle effect as a child of your SKScene subclass instead of a child of rocket. Therefore, when you remove the rocket, the particle effect won't also be removed. Just make sure you set the SKEmitter's position to be the rocket's...
objective-c,sprite-kit,skspritenode,skphysicsbody,shake
i had this same problem (also following ray's tutorials) .. You're making the camera animate by following your character which looks really cool, but it causes the stuttering. the world is moving one way, and the character is moving the opposite direction, you get a treadmill kinda thing going and...
Try adding the SKLabelNode as a child of a SKSpriteNode. SKLabelNode *label = [[SKLabelNode alloc]initWithFontNamed:@"Helvetica"]; label.position = CGPointMake(0, -label.frame.size.height/2); SKSpriteNode *background = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(label.frame.size.width, label.frame.size.height)]; background.position = CGPointMake(200, 100); [background addChild:label]; [self addChild:background]; ...
ios,sprite-kit,skspritenode,sknode
I could not get this to work, so I just gave all the birds a physicsBody, and moved the detection to didBeginContact Now it does not matter what their parent is and I don't need to worry about changing coordinates. - (void)didBeginContact:(SKPhysicsContact *)contact { SKSpriteNode *firstNode = (SKSpriteNode *)contact.bodyA.node; SKSpriteNode...
objective-c,sprite-kit,skspritenode,skphysicsbody
To improve performance, you can remove the projectiles when they are out of the screen inside the update function. override func update(currentTime: CFTimeInterval) { for node in self.children as [SKNode] { if node.name == "projectile" { if !CGRectContainsPoint(self.frame, node.position) { println("removed") node.removeFromParent() } } } } ...
ios,objective-c,sprite-kit,skspritenode
You can override the update or didEvaluateActions function of the SKScene if you want to update the node every frame. didEvaluateActions function is called in each frame after all the SKActions are evaluated. The update function is called before all actions are evaluated. override func didEvaluateActions() { if node.hasActions() {...
ios,image,swift,sprite-kit,skspritenode
You can avoid loading the images each time you change the character by creating and storing the images as textures. Here's an example of how to do that: Create an array to store the textures var textures = [SKTexture]() In didMoveToView, create and store the textures textures.append(SKTexture(imageNamed: "turtle")) textures.append(SKTexture(imageNamed: "lion"))...
objective-c,sprite-kit,skspritenode,skshapenode
If I understand your question correctly, you can achieve what you're after using the textureFromNode method on SKView. In your SKScene: -(void)didMoveToView:(SKView *)view { SKShapeNode *shape = [SKShapeNode shapeNodeWithCircleOfRadius:100]; shape.fillColor = [UIColor blueColor]; shape.position = CGPointMake(self.size.width * 0.25, self.size.height * 0.5); [self addChild:shape]; SKTexture *shapeTexture = [view textureFromNode:shape]; SKSpriteNode* sprite...
ios,sprite-kit,skspritenode,colorize
@implementation RSPaddleSprite SKSpriteNode *sprite; This makes "sprite" a global variable, so you really only have one instance referenced by sprite. This is the correct form to make sprite an ivar: @implementation RSPaddleSprite { SKSpriteNode *sprite; } More correctly stick to Cocoa naming conventions where ivars are prefixed with an underscore:...
objective-c,iphone,sprite-kit,skspritenode
Here are some observations: You your code inside of a loop which only runs once. Why are you doing that? If you are creating an object, in your case a SKSpriteNode, and want to delete it later on, you will need to keep some kind of reference to it. There...
swift,skspritenode,skphysicsbody
Physics bodies and their shapes are for physics — that is, for simulating things like collisions between sprites in your scene. Touch handling (i.e. nodeAtPoint) doesn't go through physics. That's probably the way it should be — if you had a sprite with a very small collision surface, you might...
swift,sprite-kit,opacity,skspritenode
Use SKNode's alpha property: red.alpha = 0.5 // set red to 50% transparent ...
I am not sure what you mean by the name of the sprite but I think the code sample below is the best way to check which SKSpriteNode has been touched. #import "MyScene.h" @implementation MyScene { SKSpriteNode *frank; SKSpriteNode *sally; } -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { frank...
ios,swift,sprite-kit,skspritenode
I've written a some sample code which you can adapt for your purposes: Firstly, you need π for the oscillation calculations: // Defined at global scope. let π = CGFloat(M_PI) Secondly, extend SKAction so you can easily create actions that will oscillate the node in question: extension SKAction { //...
swift,sprite-kit,private-members,skspritenode
I understand this wrong with your explanation import UIKit class SKSpriteNode { var spriteTest:String = "SpriteKitTeste"; } class Sheep: SKSpriteNode { var sheepTest:String = "SheepTest"; } let sheep = Sheep(); let someSprite:SKSpriteNode = sheep; println(someSprite.sheepTest); //SKSpriteNode does not have a member named 'sheepTest'; the super class SKSpriteNode can't access properties...
objective-c,sprite-kit,skspritenode,skaction
It makes sense that youre not seeing what you expect. you're recursively calling this method. each time addbricks is called, you get five bricks. But addbricks is calling itself.. so 5 bricks x 5 bricks x 5 bricks and so on. you have to rethink this. why are you spawning...
sprite-kit,skspritenode,sklabelnode
you can solve the problem simply by changing the properties zPosition, so you can do: labelNode.zPosition = 100; ...
swift,sprite-kit,skspritenode,skaction
Here's how you can do it with SKAction. I think using SKAction would be much smoother. Alternatively, you could also attach a physics body to the node and call applyForce to it by calculating the force of the swipe or if its a touch then calling applyImpulse with a predefined...
arrays,swift,sprite-kit,skspritenode,removechild
Yes when a node is removed from a parent it is removed from the parent in every way. There is no array automatically created for a parent and its children. If you create an array manually you'd have to remove the element manually as well. When an element is removed...
sprite-kit,skspritenode,sktexture
One way of achieving this is by composing your desired 'cookie' with SKSpriteNodes, then creating a texture to render it 'as is' to a new SpriteNode, which will then blend as a whole with the scene. In this simple example I've used a rectangle to highlight, but you could make...
arrays,sorting,swift,sprite-kit,skspritenode
To sort colorNode, you could do this: colorNode.sort() { $0.position.x < $1.position.x } ...
ios,objective-c,sprite-kit,skspritenode
I Tried and got what you are exactly looking for, BOOL isMySpriteNodeTouched = NO; mySprite = [[SKSpriteNode alloc]initWithImageNamed:@"ball"]; mySprite.position = CGPointMake(self.size.width/2.0f, self.size.height/2.0f); mySprite.name = @"mySprite"; [self addChild:mySprite]; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint touchPoint = [touch locationInNode:self]; SKNode *localNode = [[SKNode alloc]init]; localNode =...
ios,position,sprite-kit,scale,skspritenode
Go all the way back to where you created your scene. It looks like you might have your scene's scaleMode set to aspect fill, which could cause this behavior if you're designing for 3.5 and then upscaling. [scene setScaleMode:SKSceneScaleModeAspectFill]; I'd suggest switching to a different scale mode, like SKSceneScaleModeResizeFill, which...
ios,objective-c,sprite-kit,skspritenode,skaction
change your second line to CGPoint point = [touch locationInNode:self]; ...