Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help understanding Sprite & Texture

I recently started looking at cocos2d game development.

What's the difference between sprite and texture?
Maybe I could through in 'bitmap' in there. What is a bitmap?

They all seem to be the same thing as 2d image.

like image 330
eugene Avatar asked Dec 20 '25 11:12

eugene


2 Answers

A texture is an in-memory image that the device can draw onto the screen.

A sprite actually draws the texture, or just a specific rectangle of the texture, on the screen. The sprite can be scaled, rotated, positioned, skewed, tinted (colorized) among other things.

Multiple sprites can share the same texture. The texture is only loaded to memory once regardless of how many sprites are using the same texture. Moreover with CCSpriteBatchNode you can "batch" the drawing of all sprites that are using the same texture to achieve better performance.

A bitmap is a general term for a computer image where each pixel is represented by one or more bits. There's also the image format BMP which is/was popular on Windows. Most people would just say "image" these days as there are other forms of "bitmaps" that are not images. For example in AI code you often have bitmaps (arrays of bits) that represent state information of the AI or pathfinding algorithms for all areas of the game world. Ie each area in the world could have a "blocking" bit, or a "resource" bit that helps the AI making decisions.

See also Wikipedia:

  • Texture Mapping
  • Bitmap
like image 195
LearnCocos2D Avatar answered Dec 24 '25 09:12

LearnCocos2D


you can load texture into memory, for example your file with image is texture. sprite is object with set of parameters, several of them are pointer to the texture, size and texture coordinate.

you can load texture 2048x2048 into memory, then create sprite with part of this texture.

like image 20
Morion Avatar answered Dec 24 '25 09:12

Morion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!