Game Engine Andengine Summary (ix): Three ways to load image resources

Source: Internet
Author: User

In the Andengine, we load the picture resources are usually used in the assets directory loading method, the other way to use very little, perhaps because the example is only to provide the reason for this way, in fact, Andengine also provide us with the other two ways, One is commonly used in the app from the Res directory to load the picture resources (through the R.java file load), the other is loaded from the SD card or sandbox. The latter two may be smaller, but some need to be used in other ways, such as loading users ' photo resources and so on ...


1. Load resources from the assets directory, which is the most basic and most commonly used way, in many cases this is used, do not explain, the code

The traditional way to load resources under the asset directory
		Assetsbitmaptextureatlas = new Bitmaptextureatlas (Gettexturemanager (), n/a);
		Assetstextureregion = (textureregion) bitmaptextureatlastextureregionfactory.createfromasset ( Assetsbitmaptextureatlas, this 
				, "Assets_image.png", 0, 0);
		Assetsbitmaptextureatlas.load ();


2. Load the resources from the Res directory, in fact, the principle and asset is similar, just to read through the R.java file way

The traditional way to load the Res directory resources, but the resources under the RES directory will generate an index
		Resbitmaptextureatlas = new Bitmaptextureatlas (Gettexturemanager (), 128, );
		Restextureregion = (textureregion) Bitmaptextureatlastextureregionfactory.createfromresource ( Resbitmaptextureatlas, this 
				, r.drawable.res_image, 0, 0);
		Resbitmaptextureatlas.load ();
This is rarely used, and is usually placed in the assets directory.


3. Load resources from SD card, this is a key point, because some of the requirements will be used, but may not have noticed

(PS: Loading from the sandbox is the same principle, but the directory is different)

Loading resources from SD card, loading from sandbox is also the principle of
		file Resfile = new file ("/mnt/sdcard/storage_image.png");
		Sdbitmaptexturealatlas = new Bitmaptextureatlas (Gettexturemanager (), n/a);
		Filebitmaptextureatlassource Filebitmaptextureatlassource = filebitmaptextureatlassource.create (resFile);
		Sdtextureregion = (textureregion) bitmaptextureatlastextureregionfactory.createfromsource (SdBitmapTextureAlAtlas, Filebitmaptextureatlassource, 0, 0);
		Sdbitmaptexturealatlas.load ();
In fact, the principle is very simple, andengine has provided us with a class called Filebitmaptextureatlassource, And the inheritance relationship is filebitmaptextureatlassource inherit from Basetextureatlassource and implement Ibitmaptextureatlassource interface, the heart of the classmate may find, In the various create** () methods of bitmaptextureatlastextureregionfactory, the incoming source parameter is implemented on the Ibitmaptextureatlassource interface.


Brief introduction, want to deepen the classmate continue to see Andengine source bar.

Attached to my weak and weak demo source, click to download



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.