Difference between SKTexture and a Sprite in SpriteKit?

时间:2016-08-31 17:43:43

标签: sprite-kit skspritenode sktexture

im learning about SpriteKit and I dont really understand what is the Differnce between a sprite (SKSpriteNode) and a texture (SKTexture). I know both are images and is it right that "A SKSpriteNode ist a image which is drawn currently and a SKTexture only save the Data from a image to load it later in the Game so you save the image one Time and then you can put the texture in the SKSpriteNode when ever you want".

Thanks for helping ;)

1 个答案:

答案 0 :(得分:4)

A very very raw example

Just think about a UIImage and a UIImageView in UIKit. The first one is an image while the second is a UI element that can be added to a view (at a given position) and can store an image. Something similar happens with SKTexture and SKSpriteNode.

SKSpriteNode

It is first of all an SKNode.

It has a position, a rotation angle, a scale factor and a bunch of other properties included an SKTexture. You can add an SKSpriteNode as child of your GameScene (subclass of SKScene) or of another node inside the scene.

If the SKSpriteNode is added to the scene, the SKTexture associated to it is rendered on the screen according to the geometrical transformation applied to the SKSpriteNode (position, rotation, scale, etc...). If the SKSpriteNode is over the screen boundaries or is covered by another graphics element the associated texture is not rendered on the screen.

An SKSpriteNode is a node that draws a textured image, a colored square, or a textured image blended with a color. You can also provide a custom shader to create your own rendering effects.

SKTexture

Basically it is an image in bitmap format. Infact you can create an SKTexture using a UIImage and you can it to an SKSpriteNode.

A SKTexture has NOT a position, a rotation angle or many other properties you can find into a SKSpriteNode. It simply an image.

An SKTexture object is an image that can be applied to SKSpriteNode [...]. A texture object manages the texture data and graphics resources that are needed to render the image.