Skip to content

Restore LevelLoaderExample #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: GLES2-AnchorCenter
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 11 additions & 46 deletions assets/level/example.lvl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
<entity x="208" y="48" width="16" height="16" type="box"/>
<entity x="208" y="64" width="16" height="16" type="box"/>
<entity x="208" y="80" width="16" height="16" type="box"/>
<entity x="224" y="80" width="16" height="16" type="box"/>
<entity x="240" y="80" width="16" height="16" type="box"/>
<entity x="256" y="80" width="16" height="16" type="box"/>
<entity x="224" y="16" width="16" height="16" type="box"/>
<entity x="240" y="16" width="16" height="16" type="box"/>
<entity x="256" y="16" width="16" height="16" type="box"/>
<entity x="288" y="16" width="16" height="16" type="box"/>
<entity x="288" y="32" width="16" height="16" type="box"/>
<entity x="288" y="48" width="16" height="16" type="box"/>
<entity x="288" y="64" width="16" height="16" type="box"/>
<entity x="288" y="80" width="16" height="16" type="box"/>
<entity x="304" y="80" width="16" height="16" type="box"/>
<entity x="320" y="80" width="16" height="16" type="box"/>
<entity x="336" y="80" width="16" height="16" type="box"/>
<entity x="304" y="16" width="16" height="16" type="box"/>
<entity x="320" y="16" width="16" height="16" type="box"/>
<entity x="336" y="16" width="16" height="16" type="box"/>
<entity x="368" y="16" width="16" height="16" type="box"/>
<entity x="368" y="32" width="16" height="16" type="box"/>
<entity x="368" y="48" width="16" height="16" type="box"/>
Expand All @@ -54,44 +54,9 @@
<entity x="416" y="48" width="16" height="16" type="box"/>
<entity x="416" y="64" width="16" height="16" type="box"/>
<entity x="416" y="80" width="16" height="16" type="box"/>
<entity x="208" y="112" width="16" height="16" type="box"/>
<entity x="224" y="112" width="16" height="16" type="box"/>
<entity x="240" y="112" width="16" height="16" type="box"/>
<entity x="256" y="112" width="16" height="16" type="box"/>
<entity x="272" y="112" width="16" height="16" type="box"/>
<entity x="192" y="128" width="16" height="16" type="box"/>
<entity x="176" y="144" width="16" height="16" type="box"/>
<entity x="160" y="160" width="16" height="16" type="box"/>
<entity x="160" y="176" width="16" height="16" type="box"/>
<entity x="160" y="192" width="16" height="16" type="box"/>
<entity x="160" y="208" width="16" height="16" type="box"/>
<entity x="160" y="224" width="16" height="16" type="box"/>
<entity x="160" y="240" width="16" height="16" type="box"/>
<entity x="176" y="256" width="16" height="16" type="box"/>
<entity x="192" y="272" width="16" height="16" type="box"/>
<entity x="208" y="288" width="16" height="16" type="box"/>
<entity x="224" y="288" width="16" height="16" type="box"/>
<entity x="240" y="288" width="16" height="16" type="box"/>
<entity x="256" y="288" width="16" height="16" type="box"/>
<entity x="272" y="288" width="16" height="16" type="box"/>
<entity x="288" y="272" width="16" height="16" type="box"/>
<entity x="304" y="256" width="16" height="16" type="box"/>
<entity x="320" y="240" width="16" height="16" type="box"/>
<entity x="320" y="224" width="16" height="16" type="box"/>
<entity x="320" y="208" width="16" height="16" type="box"/>
<entity x="320" y="192" width="16" height="16" type="box"/>
<entity x="320" y="176" width="16" height="16" type="box"/>
<entity x="320" y="160" width="16" height="16" type="box"/>
<entity x="304" y="144" width="16" height="16" type="box"/>
<entity x="288" y="128" width="16" height="16" type="box"/>
<entity x="208" y="160" width="32" height="32" type="hexagon"/>
<entity x="256" y="160" width="32" height="32" type="hexagon"/>
<entity x="192" y="224" width="16" height="16" type="box"/>
<entity x="208" y="240" width="16" height="16" type="box"/>
<entity x="224" y="256" width="16" height="16" type="box"/>
<entity x="240" y="256" width="16" height="16" type="box"/>
<entity x="256" y="256" width="16" height="16" type="box"/>
<entity x="272" y="240" width="16" height="16" type="box"/>
<entity x="288" y="224" width="16" height="16" type="box"/>
<entity x="240" y="208" width="16" height="16" type="circle"/>

<entity x="240" y="208" width="160" height="160" type="circle">
<entity x="55" y="94" width="32" height="32" type="hexagon"/>
<entity x="108" y="94" width="32" height="32" type="hexagon"/>
</entity>
</level>
19 changes: 7 additions & 12 deletions src/org/andengine/examples/LevelLoaderExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.andengine.util.SAXUtils;
import org.andengine.util.debug.Debug;
import org.andengine.util.level.EntityLoader;
import org.andengine.util.level.LevelUtils;
import org.andengine.util.level.constants.LevelConstants;
import org.andengine.util.level.simple.SimpleLevelEntityLoaderData;
import org.andengine.util.level.simple.SimpleLevelLoader;
Expand All @@ -48,10 +49,6 @@ public class LevelLoaderExample extends SimpleBaseGameActivity {
private static final int CAMERA_HEIGHT = 320;

private static final String TAG_ENTITY = "entity";
private static final String TAG_ENTITY_ATTRIBUTE_X = "x";
private static final String TAG_ENTITY_ATTRIBUTE_Y = "y";
private static final String TAG_ENTITY_ATTRIBUTE_WIDTH = "width";
private static final String TAG_ENTITY_ATTRIBUTE_HEIGHT = "height";
private static final String TAG_ENTITY_ATTRIBUTE_TYPE = "type";

private static final Object TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BOX = "box";
Expand Down Expand Up @@ -132,26 +129,24 @@ public IEntity onLoadEntity(final String pEntityName, final IEntity pParent, fin
levelLoader.registerEntityLoader(new EntityLoader<SimpleLevelEntityLoaderData>(TAG_ENTITY) {
@Override
public IEntity onLoadEntity(final String pEntityName, final IEntity pParent, final Attributes pAttributes, final SimpleLevelEntityLoaderData pSimpleLevelEntityLoaderData) throws IOException {
final int x = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_X);
final int y = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_Y);
final int width = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_WIDTH);
final int height = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_HEIGHT);
final String type = SAXUtils.getAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_TYPE);

final VertexBufferObjectManager vertexBufferObjectManager = pSimpleLevelEntityLoaderData.getVertexBufferObjectManager();

final AnimatedSprite animatedSprite;
if(type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BOX)) {
animatedSprite = new AnimatedSprite(x, y, width, height, LevelLoaderExample.this.mBoxFaceTextureRegion, vertexBufferObjectManager);
animatedSprite = new AnimatedSprite(0, 0, LevelLoaderExample.this.mBoxFaceTextureRegion, vertexBufferObjectManager);
} else if(type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_CIRCLE)) {
animatedSprite = new AnimatedSprite(x, y, width, height, LevelLoaderExample.this.mCircleFaceTextureRegion, vertexBufferObjectManager);
animatedSprite = new AnimatedSprite(0, 0, LevelLoaderExample.this.mCircleFaceTextureRegion, vertexBufferObjectManager);
} else if(type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_TRIANGLE)) {
animatedSprite = new AnimatedSprite(x, y, width, height, LevelLoaderExample.this.mTriangleFaceTextureRegion, vertexBufferObjectManager);
animatedSprite = new AnimatedSprite(0, 0, LevelLoaderExample.this.mTriangleFaceTextureRegion, vertexBufferObjectManager);
} else if(type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_HEXAGON)) {
animatedSprite = new AnimatedSprite(x, y, width, height, LevelLoaderExample.this.mHexagonFaceTextureRegion, vertexBufferObjectManager);
animatedSprite = new AnimatedSprite(0, 0, LevelLoaderExample.this.mHexagonFaceTextureRegion, vertexBufferObjectManager);
} else {
throw new IllegalArgumentException();
}
LevelUtils.setPosition(pAttributes, animatedSprite);
LevelUtils.setSize(pAttributes, animatedSprite);

animatedSprite.animate(200);

Expand Down
3 changes: 2 additions & 1 deletion src/org/andengine/examples/launcher/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.andengine.examples.GradientExample;
import org.andengine.examples.HullAlgorithmExample;
import org.andengine.examples.ImageFormatsExample;
import org.andengine.examples.LevelLoaderExample;
import org.andengine.examples.LineExample;
import org.andengine.examples.LoadTextureExample;
import org.andengine.examples.MenuExample;
Expand Down Expand Up @@ -133,7 +134,7 @@ enum Example {
GRADIENT(GradientExample.class, R.string.example_gradient),
HULLALGORITHM(HullAlgorithmExample.class, R.string.example_hullalgorithm),
IMAGEFORMATS(ImageFormatsExample.class, R.string.example_imageformats),
// LEVELLOADER(LevelLoaderExample.class, R.string.example_levelloader),
LEVELLOADER(LevelLoaderExample.class, R.string.example_levelloader),
LINE(LineExample.class, R.string.example_line),
LOADTEXTURE(LoadTextureExample.class, R.string.example_loadtexture),
MENU(MenuExample.class, R.string.example_menu),
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/launcher/ExampleGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public enum ExampleGroup {
Example.RUNNABLEPOOLUPDATEHANDLER,
Example.SVGTEXTUREREGION,
Example.XMLLAYOUT,
// Example.LEVELLOADER,
Example.LEVELLOADER,
Example.CCBLEVELLOADER
),
APP(R.string.examplegroup_app,
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/launcher/ExampleLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ExampleLauncher extends ExpandableListActivity {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if(!AndEngine.isDeviceSupported()) {
if(!AndEngine.isDeviceSupported(this)) {
this.showDialog(ExampleLauncher.DIALOG_DEVICE_NOT_SUPPORTED);
}

Expand Down