Changing the image of a SKSprite to an SKShapeNode

前端 未结 2 1183
粉色の甜心
粉色の甜心 2021-01-21 19:00

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...

<
2条回答
  •  自闭症患者
    2021-01-21 19:20

    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.

提交回复
热议问题