Rectangle 27 0

You cannot change a SKSpriteNode image once you assign it. To do what you want, you need to create a SKSpriteNode using a texture.

- (instancetype)initWithTexture:(SKTexture *)texture

To change a SKSpriteNode's texture you assign a new texture using its texture property. You can also do this using an image converted to a texture like this:

myNode.texture = [SKTexture textureWithImageNamed:@"imageName"];

As for a SKShapeNode, you cannot assign an image. Only a path, rect, circle, ellipse or points. Look at the SKShapeNode class docs section Creating a Shape Path for more info.

No... I meant I want to assign the SKShapeNode to the SKSpriteNode's image. So sprite.texture = SKShapeNode. When I say image in the question, I really meant texture, sry

objective c - Changing the image of a SKSprite to an SKShapeNode - Sta...

objective-c sprite-kit skspritenode skshapenode
Rectangle 27 0

1. The first solution that you're suggesting SKSpriteNode with animation and texture" require the computer to load the texture to the view. If you have multiple .png files, this would mean that the computer would need to load all of these files. But if you were to use SKShapeNode, you would avoid having to do this and you would cheaply create the same looks as the SKShapeNode is not based on an image.

2. Solution 2 is the most costly to your CPU because running a video. This takes a lot of space in your memory which might even create lags if you run it on your phone.

Also, just another thing to note: If you were to extensively use Solution 1 and 2, you would end up using so much memory. But if you use the Solution 3, you will not deal with this.

Actually, SKShapeNode is the worst solution here no matter what. It requires one draw call per node and will degrade performance greatly if not used sparingly... By the way, why would you ever use SKShapeNode for this particular case, instead of a colored SKSpriteNode which, unlike SKShapeNode can be rendered in batches ? IMO, SKShapeNode is not even worth of mentioning for the current problem.

ios - SpriteKit animation - Stack Overflow

ios animation sprite-kit
Rectangle 27 0

Ahh I got it! My z-position was wrong! The created shape was on top of my backgrond image but the newly created sprite wasn't. Stupid of me...

ios - swift: converting SKShapeNode into SKSpriteNode -> No texture - ...

ios swift sprite-kit skspritenode skshapenode
Rectangle 27 0

SKShapeNode has worse performance compared to SKSpriteNode and one should try to avoid using SKShapeNode if at all possible.

Shape nodes are useful for content that cannot be easily decomposed into simple textured sprites. Shape nodes are also very useful for building and displaying debugging information on top of your game content. However, the SKSpriteNode class offers higher performance than this class, so use shape nodes sparingly.

  • Create textures for your shapes a single time, perhaps when the scene gets loaded.
  • Cache the rendered textures. In your situation a dictionary with size and texture seems appropriate, e.g. [CGSize: SKTexture].
  • From then on, whenever you need a shape, retrieve the texture from the cache and display them using an SKSpriteNode.
SKShapeNode

Renders the contents of a node tree and returns the rendered image as a SpriteKit texture.

ios - FPS drops and game slows down - Sprite-Kit and Swift - Stack Ove...

ios performance swift sprite-kit frame-rate