skspritenode

Access array in GameScene from SKSpriteNode class instance?

笑着哭i 提交于 2019-12-02 07:40:22
问题 I've created an array in my GameScene instance, and populated it inside didMove(to view: )... From an instance of an SKSpriteNode, how do I access a value in that array? So far as I know, from the template, I don't have a reference to the GameScene instance. But I could be way off on this, too. 回答1: While the answer you've linked to will solve your problem, it introduces a coupling between the node and the scene which you might regret later. A more robust solution would allow the node to

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

戏子无情 提交于 2019-12-02 06:03:41
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. (I hope this makes sense) So what I want is to stop using the duration to set the pace/speed at which

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

ObjectIdentifier needed for Swift equality?

放肆的年华 提交于 2019-12-02 03:12:52
We have multiple instances of a custom Swift class, which inherits from SKSpriteNode, and were able to execute the following code (grossly simplified for this question) correctly: let instance1 = CustomClass() let instance2 = CustomClass() let instance3 = CustomClass() let instance4 = CustomClass() let array1 = [instance1, instance2] let array2 = [instance3, instance4] func check(testInstance: CustomClass) -> Bool { return array1.filter({ $0 == testInstance }).count > 0 } check(testInstance: instance3) In other words, executing check(testInstance: instance3) returned false as expected. However

Access array in GameScene from SKSpriteNode class instance?

ぐ巨炮叔叔 提交于 2019-12-02 02:49:29
I've created an array in my GameScene instance, and populated it inside didMove(to view: )... From an instance of an SKSpriteNode, how do I access a value in that array? So far as I know, from the template, I don't have a reference to the GameScene instance. But I could be way off on this, too. While the answer you've linked to will solve your problem, it introduces a coupling between the node and the scene which you might regret later. A more robust solution would allow the node to reference whatever scene it happens to be running in, which is a common design pattern in iOS called delegate

iOS SKSpriteNode - Leave screen

为君一笑 提交于 2019-12-01 23:02:30
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 easy implement since it saves memory AndyOS Update method is where you can do it alright: - (void

SKSpriteNode setting color with UIColor

蹲街弑〆低调 提交于 2019-12-01 20:44:27
问题 I would like to set color of SKSpriteNode by Present Components Values of UIColor By Present Components Values of UIColor, I mean: (UIColor *)blackColor (UIColor *)blueColor etc The problem is that it doesn't work: SKSpriteNode *noddd = [SKSpriteNode spriteNodeWithColor:blackColor size:CGSizeMake(50, 50); Is there any possibility to do it? Thanks in advance ;) 回答1: Use an SKColor instead of UIColor. SKSpriteNode *noddd = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake

SKSpriteNode setting color with UIColor

≡放荡痞女 提交于 2019-12-01 18:37:19
I would like to set color of SKSpriteNode by Present Components Values of UIColor By Present Components Values of UIColor, I mean: (UIColor *)blackColor (UIColor *)blueColor etc The problem is that it doesn't work: SKSpriteNode *noddd = [SKSpriteNode spriteNodeWithColor:blackColor size:CGSizeMake(50, 50); Is there any possibility to do it? Thanks in advance ;) Use an SKColor instead of UIColor. SKSpriteNode *noddd = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(50, 50); 来源: https://stackoverflow.com/questions/22430743/skspritenode-setting-color-with-uicolor

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

扶醉桌前 提交于 2019-12-01 12:44:51
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 the textures to be anchored at the lower-left corner (or lower-right, depending on the direction) so

How to get SKSpriteNode by physicsBody?

▼魔方 西西 提交于 2019-12-01 12:18:19
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 code: func didBeginContact(contact: SKPhysicsContact){ switch(contact.bodyA.categoryBitMask + contact