Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add clearMenuItems() method to MenuScene; make mMenuItems protected #101

Merged
merged 1 commit into from

2 participants

@nazgee

mMenuItems field can now be cleared. It is also protected, not private any more. This makes reusing MenuScenes easier and more powerful.

src/org/andengine/entity/scene/menu/MenuScene.java
@@ -83,6 +84,15 @@ public void addMenuItem(final IMenuItem pMenuItem) {
this.registerTouchArea(pMenuItem);
}
+ public void clearMenuItems() {
+ for (Iterator<IMenuItem> iterator = mMenuItems.iterator(); iterator.hasNext();) {
@nicolasgramlich Owner

Loops using iterators are not accepted! =)

Preferred way of looping is from "size - 1" down to 0.

@nazgee
nazgee added a note

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nazgee nazgee Menu Scene is now a little bit more liberal about mMenuItems
mMenuItems can now be cleared. It is also protected, not private.
4db8c5c
@nazgee

gentle ping on this one :)

@nicolasgramlich nicolasgramlich merged commit b631d50 into nicolasgramlich:GLES2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 7, 2012
  1. @nazgee

    Menu Scene is now a little bit more liberal about mMenuItems

    nazgee authored
    mMenuItems can now be cleared. It is also protected, not private.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/org/andengine/entity/scene/menu/MenuScene.java
View
11 src/org/andengine/entity/scene/menu/MenuScene.java
@@ -1,6 +1,7 @@
package org.andengine.entity.scene.menu;
import java.util.ArrayList;
+import java.util.Iterator;
import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.CameraScene;
@@ -30,7 +31,7 @@
// Fields
// ===========================================================
- private final ArrayList<IMenuItem> mMenuItems = new ArrayList<IMenuItem>();
+ protected final ArrayList<IMenuItem> mMenuItems = new ArrayList<IMenuItem>();
private IOnMenuItemClickListener mOnMenuItemClickListener;
@@ -83,6 +84,14 @@ public void addMenuItem(final IMenuItem pMenuItem) {
this.registerTouchArea(pMenuItem);
}
+ public void clearMenuItems() {
+ for (int i = mMenuItems.size() - 1; i >= 0; i--) {
+ IMenuItem menuitem = mMenuItems.remove(i);
+ detachChild(menuitem);
+ unregisterTouchArea(menuitem);
+ }
+ }
+
@Override
public MenuScene getChildScene() {
return (MenuScene)super.getChildScene();
Something went wrong with that request. Please try again.