private void redrawNowOrLater(Image image) { if (image == null || image.isReady()) { redraw(); } else { image.addCallback(this); } }
@Override public void init() { // create and add background image layer Image backgroundImage = assetManager().getImage("images/background.png"); backgroundImage.addCallback( new ResourceCallback<Image>() { @Override public void done(Image image) { graphics().setSize(image.width(), image.height()); } @Override public void error(Throwable err) { log().error("Error loading image!", err); } }); ImageLayer backgroundLayer = graphics().createImageLayer(backgroundImage); graphics().rootLayer().add(backgroundLayer); // create a group layer to hold the peas peaLayer = graphics().createGroupLayer(); graphics().rootLayer().add(peaLayer); // preload the pea image into the asset manager cache assetManager().getImage(Pea.IMAGE); // add a listener for pointer (mouse, touch) input pointer() .setListener( new AbstractPointerListener() { @Override public void onPointerEnd(float x, float y) { Pea pea = new Pea(peaLayer, x, y); peas.add(pea); } }); }