/**
 * Copyright 2011 The PlayN Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package playn.showcase.core.sprites;

import java.util.ArrayList;
import java.util.List;

import playn.core.GroupLayer;
import playn.core.Image;
import playn.core.ImageLayer;
import playn.core.Pointer;
import playn.core.Sound;
import static playn.core.PlayN.*;

import playn.showcase.core.Demo;

public class SpritesDemo extends Demo {
  GroupLayer layer;
  List<Pea> peas = new ArrayList<Pea>(0);

  @Override
  public String name() {
    return "Sprites";
  }

  @Override
  public void init() {
    // create a group layer to hold everything
    layer = graphics().createGroupLayer();
    graphics().rootLayer().add(layer);

    // load a sound that we'll play when placing sprites
    final Sound ding = assetManager().getSound("sprites/ding");

    // create and add background image layer
    Image bgImage = assetManager().getImage("sprites/bg.png");
    ImageLayer bgLayer = graphics().createImageLayer(bgImage);
    layer.add(bgLayer);

    // add a listener for pointer (mouse, touch) input
    pointer().setListener(new Pointer.Adapter() {
      @Override
      public void onPointerEnd(Pointer.Event event) {
        Pea pea = new Pea(layer, event.x(), event.y());
        peas.add(pea);
        ding.play();
      }
    });
  }

  @Override
  public void shutdown() {
    pointer().setListener(null);

    layer.destroy();
    layer = null;
  }

  @Override
  public void paint(float alpha) {
    // layers automatically paint themselves (and their children). The rootlayer
    // will paint itself, the background, and the pea group layer automatically
    // so no need to do anything here!
  }

  @Override
  public void update(float delta) {
    for (Pea pea : peas) {
      pea.update(delta);
    }
  }
}

@@ -929,16 +929,24 @@
 emo %7B%0A  
+private 
 GroupLay
@@ -957,16 +957,24 @@
 ayer;%0A  
+private 
 List%3CPea
@@ -1004,16 +1004,38 @@
 Pea%3E(0);
+%0A  private Sound ding;
 %0A%0A  @Ove
@@ -1322,20 +1322,8 @@
     
-final Sound 
 ding
@@ -1750,33 +1750,15 @@
     
-Pea pea = new Pea(layer, 
+addPea(
 even
@@ -1786,66 +1786,221 @@
     
-  peas.add(pea);%0A        ding.play();%0A      %7D%0A    %7D
+%7D%0A    %7D);%0A    %0A    addPea(graphics().screenWidth() / 2, graphics().screenHeight() / 2);%0A  %7D%0A%0A  private void addPea(float x, float y) %7B%0A    Pea pea = new Pea(layer, x, y);%0A    peas.add(pea);%0A    ding.play(
 );%0A  %7D%0A
+  
 %0A  @

Add one starting pea in the sprite showcase demo