The ltexturelist is similar to the ltexturepack introduced by Alibaba.
The difference between the two is:
Ltexturepack focuses on "unified management of distributed textures, which combines all the smaller images in the injection into one ".
Ltexturelist focuses on "decentralized management of dispersed textures, which is called separately by retaining references of all small images ".
In fact, because the image space provided by a separate program in Android is very limited, bitmap cannot exist too much at any time no matter how effectively it is released. Ltexturelist is designed for processing massive images. After the relevant XML documents are configured, ltexturelist will only execute loadtexture with the corresponding name texture, to load ltexture (also known as "inert loading "). Instead, the load will not be completed at a time, and the cache will be generated immediately after the load once. As long as the resource is not logged out, the load will not be repeated even if the loadtexture is loaded again. Therefore, even if you enter tens of thousands of image addresses in XML, you do not have to worry about the program paralysis caused by real-time loading.
Ltexturelist is the simplest method:
Images. xml configuration:
<?xml version="1.0" standalone="yes"?><images> <ref name="hero"> <image src="assets/hero_a.png"> </image> </ref> <ref name="enemy"> <image src="assets/enemy_a.png"> </image> </ref></images>
The corresponding Java configuration is as follows:
Package Org. loon. test; import Org. loon. framework. javase. game. gamescene; import Org. loon. framework. javase. game. core. graphics. screen; import Org. loon. framework. javase. game. core. graphics. openGL. glcolor; import Org. loon. framework. javase. game. core. graphics. openGL. glex; import Org. loon. framework. javase. game. core. graphics. openGL. ltexturelist; import Org. loon. framework. javase. game. core. input. ltouch; import Org. lo On. framework. javase. game. core. input. ltransition; import Org. loon. framework. javase. game. core. timer. ltimercontext; public class ltexturelisttest extends screen {ltexturelist list; Public ltransition ontransition () {return ltransition. newempty ();} public void onload () {// set the screen background color to Red setbackground (glcolor. red); // obtain the ltexturelist instance list = new ltexturelist ("assets/images. XML ");} public Vo Id alter (ltimercontext timer) {} public void draw (glex g) {If (isonloadcomplete () {G. drawtexture (list. loadtexture ("hero"), 32, 32); G. drawtexture (list. loadtexture ("enemy"), 32, 64) ;}} public void touchdown (ltouch e) {} public void touchdrag (ltouch e) {} public void touchmove (ltouch E) {} public void touchup (ltouch e) {} public void dispose () {If (list! = NULL) {list. dispose (); List = NULL ;}} public static void main (string [] ARGs) {gamescene game = new gamescene ("ltexturelisttest", 480,320); game. setshowfps (true); game. setshowlogo (false); game. setscreen (New ltexturelisttest (); game. showscreen ();}}
After running the above program, we will get the following screen:
At this time, if there are some basic image changes and no program code needs to be modified, just fine-tune the XML parameters. For example, if we need hero to remove the black background, we only need to make the following settings:
<?xml version="1.0" standalone="yes"?><images> <ref name="hero"> <image src="assets/hero_a.png"> <mask r="0" g="0" b="0" /> </image> </ref> <ref name="enemy"> <image src="assets/enemy_a.png"> </image> </ref></images>
In this case, the <mask r = "0" G = "0" B = "0"/> line is added to the image element, that is, 0, 0 pixels are filtered out, then we execute the program again, and the screen will become as follows.
How do you find the changes? Has the original black background of the hero series disappeared? Unfortunately, this is still a group of continuous images. We cannot directly use this "Hero connection" in the game. Therefore, we need to continue to modify the XML settings, until the generated texture is accepted by the user.
<?xml version="1.0" standalone="yes"?><images> <ref name="hero"> <image src="assets/hero_a.png" x="0" y="0" w="24" h="24" scale="2"> <mask r="0" g="0" b="0" /> </image> </ref> <ref name="enemy"> <image src="assets/enemy_a.png"> </image> </ref></images>
This time, a line of text like x = "0" Y = "0" W = "24" H = "24" is added, and scale = "2" is added ". What is this? In fact, when I talked about ltexturepack in the above example, the younger brother had done something similar, but told the system to retrieve the image from x = 0 and Y = 0 of the entire image, and always got it to W = 24, H = 24 ). However, there is a significant difference between this and ltexturepack, that is, the small image obtained in ltexturepack is "virtualized" by the system from the entire large texture and does not consume any additional memory or display space, the small image taken out by ltexturelist is a real texture for the system, and an image actually exists in the display.
Of course, ltexturelist can also be used simply as an image list to set a unified setblendmode to change the image blending mode and transparency. For example:
Package Org. loon. test; import Org. loon. framework. javase. game. gamescene; import Org. loon. framework. javase. game. core. graphics. screen; import Org. loon. framework. javase. game. core. graphics. openGL. GL; import Org. loon. framework. javase. game. core. graphics. openGL. glcolor; import Org. loon. framework. javase. game. core. graphics. openGL. glex; import Org. loon. framework. javase. game. core. graphics. openGL. ltexturelist; import Org. loon. framework. javase. game. core. input. ltouch; import Org. loon. framework. javase. game. core. input. ltransition; import Org. loon. framework. javase. game. core. timer. ltimercontext; public class ltexturelisttest extends screen {ltexturelist list; Public ltransition ontransition () {return ltransition. newempty ();} public void onload () {// set the screen background color to Red setbackground (glcolor. red); List = new ltexturelist (); List. add ("assets/hero_a.png", 32, 32); list. add ("assets/enemy_a.png", 32, 64); list. setblendmode (GL. mode_color_multiply);} public void alter (ltimercontext timer) {} public void draw (glex g) {If (isonloadcomplete () {list. draw (g) ;}} public void touchdown (ltouch e) {} public void touchdrag (ltouch e) {} public void touchmove (ltouch E) {} public void touchup (ltouch e) {} public void disp Ose () {If (list! = NULL) {list. dispose (); List = NULL ;}} public static void main (string [] ARGs) {gamescene game = new gamescene ("ltexturelisttest", 480,320); game. setshowfps (true); game. setshowlogo (false); game. setscreen (New ltexturelisttest (); game. showscreen ();}}
However, this will lead to the loss of pre-setup and inertia loading capabilities.
The ltexturelist is finished, but the length of this article is still too short for the blog. So let's talk about several helper classes added in 0.3.2.
About session
The session class in lgame is designed to transfer values in multiple screens and store multiple values. The recordstore class (high-imitation javame) Simplifies the version, each time it is set, it can be a unique key-value pair or a multi-value pair in the same key. Before executing the dispose function, the value of each session save will be permanently saved (the javase version is saved as a local file, and the Android version is saved to the mobile phone database ).
The following is a simple example.
package org.loon.test;import java.util.Calendar;import org.loon.framework.javase.game.GameScene;import org.loon.framework.javase.game.core.LSystem;import org.loon.framework.javase.game.core.graphics.Screen;import org.loon.framework.javase.game.core.graphics.opengl.GLEx;import org.loon.framework.javase.game.core.input.LTouch;import org.loon.framework.javase.game.core.input.LTransition;import org.loon.framework.javase.game.core.store.Session;import org.loon.framework.javase.game.core.timer.LTimerContext;public class SessionTest extends Screen { Session session = new Session(SessionTest.class.getName()); public LTransition onTransition() { return LTransition.newEmpty(); } public void onLoad() { } public void alter(LTimerContext timer) { } public void draw(GLEx g) { g.drawString("save 0 :" + session.get("save", 0), 32, 64); g.drawString("save 1 :" + session.get("save", 1), 32, 96); } public void touchDown(LTouch e) { } public void touchDrag(LTouch e) { } public void touchMove(LTouch e) { } public void touchUp(LTouch e) { } public void dispose() { if (session != null) { session.set("save", 0, session.getInt("save", 0) + 1); session.set("save", 1, System.currentTimeMillis()); session.save(); } /** * delete session * * if (session != null) * { * session.dispose(); * session = null; * } */ } public static void main(String[] args) { GameScene game = new GameScene("SessionTest", 480, 320); game.setShowFPS(true); game.setShowLogo(false); game.setScreen(new SessionTest()); game.showScreen(); }}
Httpclient class
The httpclient class is built to ensure that the interfaces of the lgame application are consistent across platforms. The basic usage of the tool class for processing simple web page resource browsing is as follows.
HttpClient webClient = new HttpClient("www.baidu.com"); webClient.start(); System.out.println(webClient.doHTML("gb2312")); webClient.stop();
In addition to normal webpage loading, httpclient can also be used as a download tool. The basic use cases are as follows:
Package Org. loon. test; import Org. loon. framework. javase. game. gamescene; import Org. loon. framework. javase. game. action. sprite. label; import Org. loon. framework. javase. game. core. graphics. screen; import Org. loon. framework. javase. game. core. graphics. component. lbutton; import Org. loon. framework. javase. game. core. graphics. component. lprogress; import Org. loon. framework. javase. game. core. graphics. openGL. glcolor; impor T Org. loon. framework. javase. game. core. graphics. openGL. glex; import Org. loon. framework. javase. game. core. input. ltouch; import Org. loon. framework. javase. game. core. input. ltransition; import Org. loon. framework. javase. game. core. timer. ltimercontext; import org.loon.framework.e.game.net. httpclient; import org.loon.framework.e.game.net. httpdownload; import org.loon.framework.developere.game.net. httpdownloa D. httpdownloadlistener; public class downloadtest extends screen {public ltransition ontransition () {return ltransition. newempty ();} public void onload () {// setbackground (glcolor. red); // construct a character label final label Label = new label ("State: none", 200,128); label. setcolor (glcolor. white); add (Label); // build httpclient final httpclient WebClient = new httpclient ("http://libgdx.googlecode.com/files/ Libgdx-0.9.1.zip "); // build a progress bar final lprogress progress = new lprogress (32, 52,420, 50); Progress. setprogresstitle (true); add (Progress); // construct a Download button. lbutton button = new lbutton ("Download", 32, 64,100,100) {httpdownload download; // set a download tag to avoid repeated clicks Boolean downloadflag = false; Public void downclick () {If (! Downloadflag) {downloadflag = true; // progress listener final httpdownloadlistener listener = new httpdownloadlistener () {public void cancel () {label. setlabel ("State: Cancel");} public void completed () {label. setlabel ("State: completed"); downloadflag = false; If (download! = NULL) {download. save ("C: \ test.zip"); WebClient. stop () ;}} public void downloading (float c) {label. setlabel ("State: Downloading"); Progress. percent (INT) C);} public void error (exception ex) {label. setlabel ("State: error");} public void paused () {label. setlabel ("State: Paused") ;}}; runnable = new runnable () {public void run () {WebClient. start (); download = WebClient. gethttpdownload (); download. setlistener (listener); download. start () ;}}; callevent (runnable) ;}}; add (button) ;}public void alter (ltimercontext timer) {} public void draw (glex g) {} public void touchdown (ltouch e) {} public void touchdrag (ltouch e) {} public void touchmove (ltouch e) {} public void touchup (ltouch E) {} public void dispose () {} public static void main (string [] ARGs) {gamescene game = new gamescene ("downloadtest", 480,320); game. setshowfps (true); game. setshowlogo (false); game. setscreen (New downloadtest (); game. showscreen ();}}
The effect is as follows:
__________________________
In addition, in lgame SVN, there is a minor developer's 0.3.3 test version (including jar and source code, loon-simple.googlecode.com/svn/trunk /), the difference between this version and the latest version of the younger brother is only in some details (the difference is only for efficiency correction ), because the younger brother is focusing on the improvement of C # and the Development of C/C ++, the official version 0.3.3 will not be available for the moment (I will unify the C/C ++, C #, and Java versions to the 0.3.3 structure, so I will use more time ), however, the younger brother will send some recent modifications to the bottom. If you encounter some problems when using 0.3.2, you can also use the 0.3.3 test version to run the experiment, the issue may have been resolved in this version (this LGame-0.3.3-test file is updated approximately once a week, the last update was three days ago ).