0% found this document useful (0 votes)
35 views3 pages

Loading Map...

This document contains code for loading a tiled map into an E3Droid game. It defines an activity class that: 1. Creates an engine and scene for the game. 2. Displays a loading text while asynchronously loading a TMX map file from assets. 3. On map load completion, it adds the map's layers to the scene, hides the loading text, and sets the engine refresh mode. 4. If an error occurs, it displays an error message instead of hiding the loading text.

Uploaded by

Tuân Tử Tế
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Loading Map...

This document contains code for loading a tiled map into an E3Droid game. It defines an activity class that: 1. Creates an engine and scene for the game. 2. Displays a loading text while asynchronously loading a TMX map file from assets. 3. On map load completion, it adds the map's layers to the scene, hides the loading text, and sets the engine refresh mode. 4. If an error occurs, it displays an error message instead of hiding the loading text.

Uploaded by

Tuân Tử Tế
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

package Bai_9_e3droid.gioi import java.util.ArrayList; import android.os.AsyncTask; import android.util.

Log; import import import import import import import import import import import com.e3roid.E3Activity; com.e3roid.E3Engine; com.e3roid.E3Scene; com.e3roid.drawable.modifier.AlphaModifier; com.e3roid.drawable.modifier.SpanModifier; com.e3roid.drawable.sprite.TextSprite; com.e3roid.drawable.tmx.TMXException; com.e3roid.drawable.tmx.TMXLayer; com.e3roid.drawable.tmx.TMXTiledMap; com.e3roid.drawable.tmx.TMXTiledMapLoader; com.e3roid.util.Debug;

public class Bai_9_e3droidActivity extends E3Activity{ private final static int WIDTH = 320; private final static int HEIGHT = 420; private TMXTiledMap map; private ArrayList<TMXLayer> mapLayers; //-----------------------------------------------------------------------------------------@Override public E3Engine onLoadEngine() { E3Engine engine = new E3Engine(this, WIDTH, HEIGHT); engine.requestFullScreen(); engine.requestPortrait(); return engine; } //-----------------------------------------------------------------------------------------@Override public E3Scene onLoadScene() { final E3Scene scene = new E3Scene(); //Khai bo bin loadingText, khi load th ta hin th dng ch "L oading map..." final TextSprite loadingText = new TextSprite("Loading map...", 2 4, this); loadingText.move((getWidth() - loadingText.getWidth()) / 2, (getHeight() -

loadingText.getHeight()) / 2);//Ta t n g gia mn hnh loadingText.addModifier(new SpanModifier(500L, new AlphaModifier( 0, 0, 1))); scene.getTopLayer().add(loadingText); // Thc hin load maps new AsyncTask<Void,Integer,TMXTiledMap>() { @Override protected TMXTiledMap doInBackground(Void... params) { try { Log.d("doInBackground","doInBackground"); TMXTiledMapLoader mapLoader = new TMXTiledMapLoader() ;//Khai bo bin MapLoader // y ta load map t th mc Asset. Cc bn nh n h ng tn nh. ui ca n l.tmx TMXTiledMap map = mapLoader.loadFromAsset("mapgame.tm x", Bai_9_e3droidActivity.this); return map; } catch (TMXException e) { Debug.e(e.getMessage()); } return null; } @Override protected void onPostExecute(TMXTiledMap tmxTiledMap) { map = tmxTiledMap; if (tmxTiledMap != null && (mapLayers = map.getLayers()) != null) { for (TMXLayer layer : mapLayers) { Log.d("mapLayers","mapLayers"); layer.setSceneSize(getWidth(), getHeight()); //V trong maps c th c nhiu layer nn ta phi l p //ton b cc layer ny. Sau ta add vo scene. scene.getTopLayer().add(layer); scene.getTopLayer().remove(loadingText);//Ta xa b ci text hin thi khi ta load maps engine.setRefreshMode(E3Engine.REFRESH_DEFAULT); } } else {//Nu c li trong khi load th hin th thng b o sau loadingText.setText("LoadMaps Error"); loadingText.setAlpha(1); loadingText.clearModifier(); } } }.execute();

return scene;//Khi ta load maps xong ta c 1 scene nh my bi tr c } //-----------------------------------------------------------------------------------------@Override public void onLoadResources() { } //-----------------------------------------------------------------------------------------}

You might also like