LIBGDX Learning record 19--picture dynamic packaging Pixmappacker

Source: Internet
Author: User
Tags libgdx

LIBGDX, OpenGL 1.x requires that the image must be 2 of the length of the full power, generally the following workaround

1. Change OpenGL 1.x to OpenGL 2.0. (LIBGDX 1.0 version does not support 1.x, of course, there is no problem, this is for the 0.9.9 version)

2. Use Texturepacker to package the picture and add it as a large image.

The second method is a common method, but not too flexible to add, delete some of the pictures is not very convenient, large changes. Here you can consider using Pixmappacker to dynamically package the images.

Main methods:

Pack (String name, Pixmap pixmap) to package a picture and make a name

Generateatlas (TextureFilter minfilter, TextureFilter magfilter, Boolean usemipmap) generate Picture Resource bundle

Example code:

1  Packagecom.fxb.newtest;2 3 ImportCom.badlogic.gdx.ApplicationAdapter;4 ImportCom.badlogic.gdx.Gdx;5 Importcom.badlogic.gdx.graphics.GL10;6 ImportCom.badlogic.gdx.graphics.Pixmap;7 ImportCom.badlogic.gdx.graphics.Pixmap.Format;8 ImportCom.badlogic.gdx.graphics.Texture.TextureFilter;9 ImportCom.badlogic.gdx.graphics.g2d.PixmapPacker;Ten ImportCom.badlogic.gdx.graphics.g2d.SpriteBatch; One ImportCom.badlogic.gdx.graphics.g2d.TextureAtlas; A Importcom.badlogic.gdx.graphics.g2d.TextureRegion; -  -  Public classLib019_texturepackextendsapplicationadapter{ the  - Textureatlas Atlas; - textureregion Region1, Region2; - spritebatch Batch; +      - @Override +      Public voidCreate () { A         //TODO auto-generated Method Stub at         Super. Create (); -          -Pixmappacker Packer =NewPixmappacker (format.rgb565, 2,true ); -         //Packer.pack ("First", PIXMAP1); -Pixmap PIXMAP1 =NewPixmap (Gdx.files.internal ("Data/badlogic.jpg" ) ); -Pixmap PIXMAP2 =NewPixmap (Gdx.files.internal ("Data/pal4_1.jpg" ) ); inPacker.pack ("First", PIXMAP1); -Packer.pack ("Second", PIXMAP2); to          +Atlas = Packer.generatetextureatlas (Texturefilter.nearest, Texturefilter.nearest,false ); -Region1 = Atlas.findregion ("First" ); theRegion2 = Atlas.findregion ("Second" ); *          $ pixmap1.dispose ();Panax Notoginseng pixmap2.dispose (); -          theBatch =NewSpriteBatch (); +     } A  the @Override +      Public voidrender () { -         //TODO auto-generated Method Stub $         Super. Render (); $Gdx.gl.glClearColor (0, 1, 1, 1 ); - Gdx.gl.glClear (gl10.gl_color_buffer_bit); -          the Batch.begin (); -Batch.draw (Region1, 10, 10 );WuyiBatch.draw (Region2, 20+region1.getregionwidth (), 10 ); the batch.end (); -          Wu     } -  About @Override $      Public voidDispose () { -         //TODO auto-generated Method Stub - atlas.dispose (); -         Super. Dispose (); A     } +  the}

Operation Result:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.