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);
}
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations