mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
102 lines
3.7 KiB
Java
102 lines
3.7 KiB
Java
/*******************************************************************************
|
|
* Copyright (c) 2013, Esoteric Software
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
* list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
******************************************************************************/
|
|
|
|
package com.esotericsoftware.spine;
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
|
import com.badlogic.gdx.graphics.GL10;
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
|
|
public class AnimationStateTest extends ApplicationAdapter {
|
|
SpriteBatch batch;
|
|
ShapeRenderer renderer;
|
|
|
|
TextureAtlas atlas;
|
|
Skeleton skeleton;
|
|
Animation walkAnimation;
|
|
Animation jumpAnimation;
|
|
Bone root;
|
|
AnimationState state;
|
|
|
|
public void create () {
|
|
batch = new SpriteBatch();
|
|
renderer = new ShapeRenderer();
|
|
|
|
atlas = new TextureAtlas(Gdx.files.internal("spineboy.atlas"));
|
|
SkeletonJson json = new SkeletonJson(atlas);
|
|
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy-skeleton.json"));
|
|
walkAnimation = json.readAnimation(Gdx.files.internal("spineboy-walk.json"), skeletonData);
|
|
jumpAnimation = json.readAnimation(Gdx.files.internal("spineboy-jump.json"), skeletonData);
|
|
|
|
// Define mixing between animations.
|
|
AnimationStateData mixing = new AnimationStateData();
|
|
mixing.setMixing(walkAnimation, jumpAnimation, 0.4f);
|
|
|
|
state = new AnimationState(mixing);
|
|
state.setAnimation(walkAnimation, true);
|
|
|
|
skeleton = new Skeleton(skeletonData);
|
|
|
|
root = skeleton.getRootBone();
|
|
root.setX(250);
|
|
root.setY(20);
|
|
|
|
skeleton.updateWorldTransform();
|
|
}
|
|
|
|
public void render () {
|
|
state.update(Gdx.graphics.getDeltaTime() / 3);
|
|
|
|
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
|
|
batch.begin();
|
|
|
|
System.out.println(skeleton);
|
|
state.apply(skeleton);
|
|
// After one second, change the current animation. Mixing is done by AnimationState for you.
|
|
if (state.getTime() > 1 && state.getAnimation() == walkAnimation) state.setAnimation(jumpAnimation, false);
|
|
skeleton.updateWorldTransform();
|
|
skeleton.draw(batch);
|
|
|
|
batch.end();
|
|
}
|
|
|
|
public void resize (int width, int height) {
|
|
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
|
|
renderer.setProjectionMatrix(batch.getProjectionMatrix());
|
|
}
|
|
|
|
public void dispose () {
|
|
atlas.dispose();
|
|
}
|
|
|
|
public static void main (String[] args) throws Exception {
|
|
new LwjglApplication(new AnimationStateTest());
|
|
}
|
|
}
|