Texturepacker polygon1/25/2024 internal ( "image.png" )) sprite = new Sprite ( texture, 20, 20, 50, 50 ) sprite. The Sprite class (source) describes both a texture region, the geometry where it will be drawn, and the color it will be drawn. SpriteBatch has many methods for drawing a texture region: Method signatureĭraw(TextureRegion region, float x, float y)ĭraws the region using the width and height of the region.ĭraw(TextureRegion region, float x, float y,ĭraws the region, stretched to the width and height.įloat scaleX, float scaleY, float rotation)ĭraws the region, stretched to the width and height, and scaled and rotated around an origin. The same can be achieved by passing the Texture and other parameters to SpriteBatch, but TextureRegion makes it convenient to have a single object that describes both. Here the 20, 20, 50, 50 describes the portion of the texture, which is then drawn at 10,10. internal ( "image.png" )) region = new TextureRegion ( texture, 20, 20, 50, 50 ). The TextureRegion class (source) describes a rectangle inside a texture and is useful for drawing only a portion of the texture. This can be used to draw any quadrilateral, not just rectangles. This is an advanced method for passing in the raw geometry, texture coordinates, and color information. This is a somewhat advanced method as it uses texture coordinates from 0-1 rather than pixel coordinates.ĭraw(Texture texture, float spriteVertices, int offset, int length) This draws a portion of a texture, stretched to the width and height. This monster method draws a portion of a texture, stretched to the width and height, scaled and rotated around an origin, and optionally flipped. Int srcX, int srcY, int srcWidth, int srcHeight, Int srcWidth, int srcHeight, boolean flipX, boolean flipY)ĭraws a portion of a texture, stretched to the width and height, and optionally flipped.įloat originX, float originY, float width, float height,įloat scaleX, float scaleY, float rotation, Int srcX, int srcY, int srcWidth, int srcHeight)įloat width, float height, int srcX, int srcY, SpriteBatch has many methods for drawing a texture: Method signatureĭraws the texture using the texture’s width and height The texture will be drawn in a rectangle positioned at 10,10 with a width and height equal to the size of the texture. Here a texture is created and passed to a SpriteBatch to be drawn. Using SpriteBatch (source) in an application looks like this: For these reasons, it is common to store many smaller images in a larger image and then draw regions of the larger image to both maximize geometry batching and avoid texture changes. Also, binding a texture is a somewhat expensive operation. If it is given a texture different than the last texture, then it binds the last texture, submits the collected geometry to be drawn, and begins collecting geometry for the new texture.Ĭhanging textures every few rectangles that are drawn prevents SpriteBatch from batching much geometry. It collects the geometry without submitting it to the GPU. SpriteBatch is given a texture and coordinates for each rectangle to be drawn. Instead, many rectangles for the same texture can be described and sent to the GPU all at once. It would be inefficient to send each rectangle one at a time to the GPU to be drawn. It is also very common to draw the same texture or various regions of that texture many times. It is very common to draw a texture mapped to rectangular geometry. This means that the geometry is specified in pixels, which makes it easy to draw textures in the appropriate size and position on the screen. Many 2D games configure the viewport to match the screen resolution. The size and position on the screen that the texture is drawn is determined by both the geometry and how the OpenGL viewport is configured. To do the actual drawing, first the texture is bound (i.e., made the current texture), then the geometry is given to OpenGL to draw. A rectangle that is a subset of a texture is called a texture region. For example, the geometry could be a rectangle and the texture could be applied so that each corner of the rectangle corresponds to a corner of the texture. To draw a texture, geometry is described and the texture is applied by specifying where each vertex in the geometry corresponds on the texture. Drawing imagesĪn image that has been decoded from its original format (e.g., PNG) and uploaded to the GPU is called a texture. This page gives a brief overview of how images are drawn using OpenGL and how libGDX simplifies and optimizes the task through the SpriteBatch class.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |