Search in sources :

Example 6 with SpineRenderer

use of com.bladecoder.engine.spine.SpineRenderer in project bladecoder-adventure-engine by bladecoder.

the class ScnWidget method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();
    Color tmp = batch.getColor();
    batch.setColor(Color.WHITE);
    if (scn != null && !loading && !loadingError) {
        // BACKGROUND
        batch.disableBlending();
        tile.draw(batch, getX(), getY(), getWidth(), getHeight());
        batch.enableBlending();
        Vector3 v = new Vector3(getX(), getY(), 0);
        v = v.prj(batch.getTransformMatrix());
        batch.end();
        HdpiUtils.glViewport((int) v.x, (int) v.y, (int) getWidth(), (int) (getHeight()));
        getStage().calculateScissors(bounds, scissors);
        if (ScissorStack.pushScissors(scissors)) {
            // WORLD CAMERA
            sceneBatch.setProjectionMatrix(camera.combined);
            sceneBatch.begin();
            Array<AtlasRegion> scnBackground = scn.getBackground();
            if (scnBackground != null) {
                sceneBatch.disableBlending();
                float x = 0;
                for (AtlasRegion tile : scnBackground) {
                    sceneBatch.draw(tile, x, 0f);
                    x += tile.getRegionWidth();
                }
                sceneBatch.enableBlending();
            }
            // draw layers from bottom to top
            List<SceneLayer> layers = scn.getLayers();
            for (int i = layers.size() - 1; i >= 0; i--) {
                SceneLayer layer = layers.get(i);
                if (!layer.isVisible())
                    continue;
                List<InteractiveActor> actors = layer.getActors();
                for (InteractiveActor a : actors) {
                    if (a instanceof SpriteActor) {
                        boolean visibility = a.isVisible();
                        a.setVisible(true);
                        ((SpriteActor) a).draw(sceneBatch);
                        a.setVisible(visibility);
                    }
                }
            }
            sceneBatch.end();
            ScissorStack.popScissors();
        }
        drawer.drawBGBounds();
        if (showWalkZone && scn.getPolygonalNavGraph() != null) {
            drawer.drawBBoxWalkZone(scn, false);
            drawer.drawPolygonVertices(scn.getPolygonalNavGraph().getWalkZone(), Color.GREEN);
        }
        drawer.drawBBoxActors(scn);
        if (selectedActor != null) {
            drawer.drawSelectedActor(selectedActor);
        }
        getStage().getViewport().apply();
        // SCREEN CAMERA
        batch.begin();
        drawFakeDepthMarkers((SpriteBatch) batch);
        if (!inScene) {
            faRenderer.draw((SpriteBatch) batch);
        }
        // DRAW COORDS
        Vector2 coords = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        screenToWorldCoords(coords);
        String str = MessageFormat.format("({0}, {1})", (int) coords.x, (int) coords.y);
        textLayout.setText(defaultFont, str);
        RectangleRenderer.draw((SpriteBatch) batch, 0f, getY() + getHeight() - textLayout.height - 15, textLayout.width + 10, textLayout.height + 10, BLACK_TRANSPARENT);
        defaultFont.draw(batch, textLayout, 5, getHeight() + getY() - 10);
        batch.setColor(tmp);
    } else {
        background.draw(batch, getX(), getY(), getWidth(), getHeight());
        String s;
        if (loading) {
            s = "LOADING...";
            Timer.post(new Task() {

                @Override
                public void run() {
                    loading = false;
                    try {
                        EngineAssetManager.getInstance().finishLoading();
                        scn.retrieveAssets();
                        // disable Spine events
                        for (BaseActor a : scn.getActors().values()) {
                            if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof SpineRenderer) {
                                ((SpineRenderer) ((SpriteActor) a).getRenderer()).enableEvents(false);
                            }
                        }
                        drawer.setCamera(camera);
                        invalidate();
                    } catch (Exception e) {
                        Message.showMsg(getStage(), "Could not load assets for scene", 4);
                        EditorLogger.printStackTrace(e);
                        loadingError = true;
                        loading = false;
                    }
                }
            });
        } else if (loadingError) {
            s = "ERROR IN SCENE DATA. CANNOT DISPLAY SCENE";
        } else if (Ctx.project.getProjectDir() == null) {
            s = "CREATE OR LOAD A PROJECT";
        } else {
            s = "THERE ARE NO SCENES IN THIS CHAPTER YET";
        }
        textLayout.setText(bigFont, s);
        bigFont.draw(batch, textLayout, (getWidth() - textLayout.width) / 2, getHeight() / 2 + bigFont.getLineHeight() * 3);
    }
}
Also used : Task(com.badlogic.gdx.utils.Timer.Task) SceneLayer(com.bladecoder.engine.model.SceneLayer) Color(com.badlogic.gdx.graphics.Color) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Vector3(com.badlogic.gdx.math.Vector3) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) Vector2(com.badlogic.gdx.math.Vector2) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)

Example 7 with SpineRenderer

use of com.bladecoder.engine.spine.SpineRenderer in project bladecoder-adventure-engine by bladecoder.

the class EditAnimationDialog method getSources.

private String[] getSources() {
    String path = null;
    ActorRenderer renderer = parent.getRenderer();
    if (renderer instanceof AtlasRenderer) {
        path = Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/" + Ctx.project.getResDir();
        ext = EngineAssetManager.ATLAS_EXT;
    } else if (renderer instanceof Sprite3DRenderer) {
        path = Ctx.project.getAssetPath() + Project.SPRITE3D_PATH;
        ext = EngineAssetManager.MODEL3D_EXT;
    } else if (renderer instanceof SpineRenderer) {
        path = Ctx.project.getAssetPath() + Project.SPINE_PATH;
        ext = EngineAssetManager.SPINE_EXT;
    } else if (renderer instanceof ImageRenderer) {
        path = Ctx.project.getAssetPath() + Project.IMAGE_PATH + "/" + Ctx.project.getResDir();
        ext = "";
    }
    File f = new File(path);
    String[] sources = f.list(new FilenameFilter() {

        @Override
        public boolean accept(File arg0, String arg1) {
            if (arg1.endsWith(ext))
                return true;
            return false;
        }
    });
    if (sources != null) {
        Arrays.sort(sources);
        for (int i = 0; i < sources.length; i++) sources[i] = sources[i].substring(0, sources[i].length() - ext.length());
    } else {
        sources = new String[0];
    }
    return sources;
}
Also used : ImageRenderer(com.bladecoder.engine.model.ImageRenderer) FilenameFilter(java.io.FilenameFilter) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) ActorRenderer(com.bladecoder.engine.model.ActorRenderer) File(java.io.File)

Example 8 with SpineRenderer

use of com.bladecoder.engine.spine.SpineRenderer in project bladecoder-adventure-engine by bladecoder.

the class EditAnimationDialog method setSource.

private void setSource() {
    AnimationDesc anim = null;
    ActorRenderer renderer = parent.getRenderer();
    String sourceStr = source.getText();
    if (renderer instanceof SpineRenderer) {
        anim = new SpineAnimationDesc();
        if (spineAtlasExists(sourceStr)) {
            ((SpineAnimationDesc) anim).atlas = null;
            setVisible(atlas, false);
        } else {
            if (!atlas.isVisible()) {
                setVisible(atlas, true);
            }
            ((SpineAnimationDesc) anim).atlas = atlas.getText();
        }
    } else if (renderer instanceof AtlasRenderer) {
        anim = new AtlasAnimationDesc();
    } else {
        anim = new AnimationDesc();
    }
    anim.source = sourceStr;
    anim.count = Tween.INFINITY;
    anim.preload = true;
    anim.disposeWhenPlayed = false;
    if (renderer instanceof SpineRenderer) {
        spriteWidget.setSource(Project.SPINE_RENDERER_STRING, anim);
    } else if (renderer instanceof AtlasRenderer) {
        spriteWidget.setSource(Project.ATLAS_RENDERER_STRING, anim);
    } else if (renderer instanceof ImageRenderer) {
        spriteWidget.setSource(Project.IMAGE_RENDERER_STRING, anim);
    } else if (renderer instanceof Sprite3DRenderer) {
        spriteWidget.setSource(Project.S3D_RENDERER_STRING, anim);
    }
}
Also used : AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) ActorRenderer(com.bladecoder.engine.model.ActorRenderer)

Example 9 with SpineRenderer

use of com.bladecoder.engine.spine.SpineRenderer in project bladecoder-adventure-engine by bladecoder.

the class SpineSecondaryAnimationAction method run.

@Override
public boolean run(VerbRunner cb) {
    String actorId = animation.getActorId();
    SpriteActor a = (SpriteActor) World.getInstance().getCurrentScene().getActor(actorId, true);
    if (a.getRenderer() instanceof SpineRenderer) {
        SpineRenderer r = (SpineRenderer) a.getRenderer();
        String anim = animation.getAnimationId();
        if (anim.isEmpty())
            anim = null;
        r.setSecondaryAnimation(anim);
    } else {
        EngineLogger.error("SpineSecondaryAnimation: The actor renderer has to be of Spine type.");
    }
    return false;
}
Also used : SpriteActor(com.bladecoder.engine.model.SpriteActor) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer)

Example 10 with SpineRenderer

use of com.bladecoder.engine.spine.SpineRenderer in project bladecoder-adventure-engine by bladecoder.

the class SpineSkinAction method run.

@Override
public boolean run(VerbRunner cb) {
    SpriteActor a = (SpriteActor) actor.getActor();
    if (a instanceof SpriteActor && a.getRenderer() instanceof SpineRenderer) {
        SpineRenderer r = (SpineRenderer) a.getRenderer();
        r.setSkin(skin);
    } else {
        EngineLogger.error("SpineSecondaryAnimation: The actor renderer has to be of Spine type.");
    }
    return false;
}
Also used : SpriteActor(com.bladecoder.engine.model.SpriteActor) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer)

Aggregations

SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)10 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)7 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)7 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)6 SpriteActor (com.bladecoder.engine.model.SpriteActor)6 Vector2 (com.badlogic.gdx.math.Vector2)5 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)4 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)3 AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)2 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)2 AnchorActor (com.bladecoder.engine.model.AnchorActor)2 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)2 BaseActor (com.bladecoder.engine.model.BaseActor)2 CharacterActor (com.bladecoder.engine.model.CharacterActor)2 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)2 ParticleRenderer (com.bladecoder.engine.model.ParticleRenderer)2 SceneLayer (com.bladecoder.engine.model.SceneLayer)2 TextRenderer (com.bladecoder.engine.model.TextRenderer)2 Color (com.badlogic.gdx.graphics.Color)1