Example usage for com.badlogic.gdx.scenes.scene2d.actions RemoveActorAction RemoveActorAction

List of usage examples for com.badlogic.gdx.scenes.scene2d.actions RemoveActorAction RemoveActorAction

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.actions RemoveActorAction RemoveActorAction.

Prototype

RemoveActorAction

Source Link

Usage

From source file:com.ray3k.skincomposer.MenuList.java

License:Open Source License

public void hide() {
    //fade out and then remove
    clearActions();/*  w w w. j  a v a  2  s  .c o  m*/
    AlphaAction alphaAction = new AlphaAction();
    alphaAction.setAlpha(0.0f);
    alphaAction.setDuration(.3f);
    alphaAction.setInterpolation(Interpolation.fade);
    RemoveActorAction removeAction = new RemoveActorAction();
    removeAction.setActor(this);
    SequenceAction sequenceAction = new SequenceAction(alphaAction, removeAction);
    addAction(sequenceAction);
}

From source file:com.sandeel.bushidoblocks.PlayScreen.java

License:Open Source License

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);/*  w w  w .j a  va2  s  .c  o  m*/
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    //if out of time
    if (timer.getTimeRemaining() <= 0) {

        music.stop();

        //save the score
        prefs.putInteger("lastScore", points);
        prefs.flush();

        //update high score
        if (points > prefs.getInteger("highScore")) {
            prefs.putInteger("highScore", points);
            prefs.flush();
        }

        game.setScreen(new GameOverScreen(game));
    }

    camera.update();
    batch.setProjectionMatrix(camera.combined);
    batch.begin();

    //draw background
    batch.draw(background, 0, 0);

    //display remaining time
    font.draw(batch, "time", 60, (800 - 100));
    numbersFont.draw(batch, String.valueOf(timer.getTimeRemainingInSeconds()), 80, (800 - 150));

    //display score
    font.draw(batch, "score", (480 - 180), (800 - 100));
    scoreFont.draw(batch, String.valueOf(points), (480 - 170), (800 - 150));

    gridSpaces = grid.getSpaces();
    it = gridSpaces.iterator();

    while (it.hasNext()) {
        space = it.next();

        // move block down if needed
        if (space.hasBlock()) {
            if (!space.onBottomRow() && !space.getGridSpaceBelow().hasBlock()) {
                space.getGrid().moveBlock(space, space.getGridSpaceBelow());
            }
        }

        if (space.hasBlock()) {
            blockPointer = blockImages[space.getBlock().getColour().ordinal()];

            //update block
            space.getBlock().update();

            //draw block
            batch.draw(blockPointer, space.getBlock().getRectangle().getX(),
                    space.getBlock().getRectangle().getY() + space.getBlock().getYOffset());
        }
    }
    batch.end();

    /* add new blocks if spaces in top row empty */
    for (GridSpace space : grid.getTopRow()) {

        if (!space.hasBlock()) {
            boolean hasSuperBlock = grid.hasSuperBlock();

            /* add a super block if there are no matches and no super blocks and no spaces left
            * get out of jail card!!
            */
            if (!hasSuperBlock && grid.countEmptySpaces() == 1 && !grid.hasMatch()) {
                space.spawnBlock(COLOURS.SUPER_2WAYS);
            }
            // chance of super block if none on table
            else if (!hasSuperBlock) {
                int chance = 18;
                int c = (int) (Math.random() * (chance));
                if (c == 1) {
                    // if the space is on an edge make it a two ways block
                    // if not, a random super block
                    if (!space.hasGridSpaceBelow() || !space.hasGridSpaceLeft() || !space.hasGridSpaceRight()) {
                        space.spawnBlock(COLOURS.SUPER_2WAYS);
                    } else {
                        space.spawnSuperBlock();
                    }
                } else {
                    space.spawnBlock();
                }
                //normal block if already superblocks
            } else {
                space.spawnBlock();
            }

            // give the block an offset to make it fall
            space.getBlock().setYOffset(space.getBlock().getYOffset() + (60));
            if (space.getGridSpaceBelow().hasBlock()) {
                space.getBlock().setYOffset(space.getGridSpaceBelow().getBlock().getYOffset() + 200);
            }
        }
    }

    /* if user has tapped screen or clicked */
    if (Gdx.input.justTouched()) {

        if (paused == true) {
            paused = false;
            timer.start();
        }

        Vector3 touchPos = new Vector3();
        touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
        camera.unproject(touchPos);

        gridSpaces = grid.getSpaces();
        it = gridSpaces.iterator();
        while (it.hasNext()) {
            space = it.next();
            if (space.hasBlock() && space.getBlock().getRectangle().contains(touchPos.x, touchPos.y)) {

                /* handle super blocks */
                if (space.getBlock().getColour() == COLOURS.SUPER_HORIZONTAL) {
                    if (prefs.getBoolean("soundOn") == true) {
                        crack.play();
                    }
                    Gdx.input.vibrate(200);
                    for (GridSpace targetSpace : grid.getRow(space.getY())) {
                        targetSpace.deleteBlock();
                    }
                } else if (space.getBlock().getColour() == COLOURS.SUPER_VERTICAL) {
                    if (prefs.getBoolean("soundOn") == true) {
                        crack.play();
                    }
                    Gdx.input.vibrate(200);
                    for (GridSpace targetSpace : grid.getColumn(space.getX())) {
                        targetSpace.deleteBlock();
                    }
                } else if (space.getBlock().getColour() == COLOURS.SUPER_2WAYS) {
                    if (prefs.getBoolean("soundOn") == true) {
                        crack.play();
                    }
                    Gdx.input.vibrate(200);
                    for (GridSpace targetSpace : grid.getRow(space.getY())) {
                        targetSpace.deleteBlock();
                    }
                    for (GridSpace targetSpace : grid.getColumn(space.getX())) {
                        targetSpace.deleteBlock();
                    }
                    Gdx.input.vibrate(200);
                    /* now handle normal blocks */
                } else {
                    HashSet<GridSpace> emptyMatches = new HashSet<GridSpace>();
                    HashSet<GridSpace> matches = space.getGrid().getMatches(space.getX(), space.getY(),
                            space.getBlock().getColour(), emptyMatches);

                    /* if got a match */
                    if (matches.size() >= 3) {
                        // play a sound
                        if (prefs.getBoolean("soundOn") == true) {
                            whoosh.play();
                        }
                        Gdx.input.vibrate(50);

                        for (GridSpace match : matches) {
                            // delete the blocks
                            match.deleteBlock();
                        }
                        // add time
                        int timeReceived = (1 * (matches.size()) / 4);
                        timer.addTime(timeReceived);

                        // give player points for each block
                        int amount = 10 * matches.size();

                        // add a multiplier for large amounts of blocks
                        int bonus = amount * (matches.size() - 2);

                        points += (amount + bonus);

                        Label label = new Label(String.valueOf(amount + bonus), labelStyle);

                        label.setPosition(touchPos.x - (label.getWidth() / 2), touchPos.y);

                        MoveToAction action = new MoveToAction();
                        action.setPosition(touchPos.x - (label.getWidth() / 2), (touchPos.y + 800));
                        action.setDuration(1.2f);

                        label.addAction(Actions.sequence(action, new RemoveActorAction()));

                        stage.addActor(label);
                    }
                }
            }
        }
    }

    // draw the actors
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}