Example usage for com.badlogic.gdx.utils ObjectMap clear

List of usage examples for com.badlogic.gdx.utils ObjectMap clear

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ObjectMap clear.

Prototype

public void clear() 

Source Link

Usage

From source file:com.pastew.autogearbox.handlers.Box2DSprite.java

License:Apache License

/** draws all the {@link Box2DSprite Box2DSprites} on the {@link Body} or {@link Fixture} that hold them in their user data in the given {@link World} */
public static void draw(Batch batch, World world, boolean sortByZ) {
    @SuppressWarnings("unchecked")
    Array<Body> tmpBodies = Pools.obtain(Array.class);
    world.getBodies(tmpBodies);/*from w  w  w  . j a va  2  s  .com*/

    if (sortByZ) {
        @SuppressWarnings("unchecked")
        ObjectMap<Box2DSprite, Object> tmpZMap = Pools.obtain(ObjectMap.class);
        tmpZMap.clear();
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpZMap.put(tmpBox2DSprite, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpZMap.put(tmpBox2DSprite, fixture);
        }

        @SuppressWarnings("unchecked")
        Array<Box2DSprite> tmpKeys = Pools.obtain(Array.class);
        Iterator<Box2DSprite> keys = tmpZMap.keys();
        while (keys.hasNext())
            tmpKeys.add(keys.next());
        tmpKeys.sort(zComparator);
        for (Box2DSprite key : tmpKeys) {
            Object value = tmpZMap.get(key);
            if (value instanceof Body)
                key.draw(batch, (Body) value);
            else
                key.draw(batch, (Fixture) value);
        }

        tmpKeys.clear();
        tmpZMap.clear();
        Pools.free(tmpKeys);
        Pools.free(tmpZMap);
    } else
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpBox2DSprite.draw(batch, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpBox2DSprite.draw(batch, fixture);
        }

    tmpBodies.clear();
    Pools.free(tmpBodies);
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.graphics.Box2DSprite.java

License:Apache License

/** draws all the {@link Box2DSprite Box2DSprites} on the {@link Body} or {@link Fixture} that hold them in their user data in the given {@link World} */
public static void draw(Batch batch, World world, boolean sortByZ) {
    @SuppressWarnings("unchecked")
    Array<Body> tmpBodies = Pools.obtain(Array.class);
    Box2DSprite tmpBox2DSprite;/* ww  w .j a v  a 2 s.c o  m*/

    world.getBodies(tmpBodies);

    if (sortByZ) {
        @SuppressWarnings("unchecked")
        ObjectMap<Box2DSprite, Object> tmpZMap = Pools.obtain(ObjectMap.class);
        tmpZMap.clear();
        for (Body body : tmpBodies) {
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpZMap.put(tmpBox2DSprite, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpZMap.put(tmpBox2DSprite, fixture);
        }

        @SuppressWarnings("unchecked")
        Array<Box2DSprite> tmpKeys = Pools.obtain(Array.class);
        Iterator<Box2DSprite> keys = tmpZMap.keys();
        while (keys.hasNext())
            tmpKeys.add(keys.next());
        tmpKeys.sort(zComparator);
        for (Box2DSprite key : tmpKeys) {
            Object value = tmpZMap.get(key);
            if (value instanceof Body)
                key.draw(batch, (Body) value);
            else
                key.draw(batch, (Fixture) value);
        }

        tmpKeys.clear();
        tmpZMap.clear();
        Pools.free(tmpKeys);
        Pools.free(tmpZMap);
    } else
        for (Body body : tmpBodies) {
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpBox2DSprite.draw(batch, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpBox2DSprite.draw(batch, fixture);
        }

    tmpBodies.clear();
    Pools.free(tmpBodies);
}