dimanche 4 septembre 2016

Eclipse changing characters with keypress

a newbie here. I just started using Eclipse and I am already having some trouble. Prior to this, the extent of my coding "skills" was pressing buttons and adding values in Game Maker and having the game figure out the rest. Anyway I started this mini project of mine because GameMaker unfortunately doesn't work with .skel files so I decided to create a little application that allows me to view the file. What I am trying to do is quite simple. I have two characters. Each one has their own .skle file, .atlas file, and a different name for their animation. Basically what I want to know is how to program it so that whenever I press a key, it changes to the character the key is assigned to. It seems as if every different extension has their own set of rules. I have followed lots of tutorials online but the ones I often come across are about things that deal with JFrames or texted data which rely on one file or information. I am not sure if I should be grouping things or giving each character their own Class.I have been messing around with the code a bit and this is where I am now.

public class skellycrazy extends ApplicationAdapter {
    OrthographicCamera camera;
    PolygonSpriteBatch batch;
    SkeletonRenderer renderer;
    SkeletonRendererDebug debugRenderer;    
    TextureAtlas atlas;
    Skeleton skeleton;
    AnimationState state;

public void create () {

    camera = new OrthographicCamera();
    batch = new PolygonSpriteBatch();
    renderer = new SkeletonRenderer();
    renderer.setPremultipliedAlpha(true); // PMA results in correct blending without outlines.
    debugRenderer = new SkeletonRendererDebug();
    debugRenderer.setBoundingBoxes(false);
    debugRenderer.setRegionAttachments(false);

if (Gdx.input.isKeyPressed(Input.Keys.B))
    {   
        atlas = new TextureAtlas(Gdx.files.internal("example.movingleft.atlas"));
        SkeletonBinary skel = new SkeletonBinary(atlas); // This loads skeleton JSON data, which is stateless.
        skel.setScale(1.2f); // Load the skeleton at 60% the size it was in Spine.
        SkeletonData skeletonData = skel.readSkeletonData(Gdx.files.internal("example.movingleft.skel"));

        skeleton = new Skeleton(skeletonData); // Skeleton holds skeleton state (bone positions, slot attachments, etc).
        skeleton.setPosition(400, 100);

        AnimationStateData stateData = new AnimationStateData(skeletonData); 
        stateData.setMix("left", "left", 0.2f);

        state = new AnimationState(stateData); // Holds the animation state for a skeleton
        state.addAnimation(0, "left", true, 0);     
    }

if (Gdx.input.isKeyPressed(Input.Keys.V))
    {
        atlas = new TextureAtlas(Gdx.files.internal("example.movingright.atlas"));
        SkeletonBinary skel = new SkeletonBinary(atlas); // This loads skeleton JSON data, which is stateless.
        skel.setScale(1.2f); // Load the skeleton at 60% the size it was in Spine.
        SkeletonData skeletonData = skel.readSkeletonData(Gdx.files.internal("example.movingright.skel"));

        skeleton = new Skeleton(skeletonData); // Skeleton holds skeleton state (bone positions, slot attachments, etc).
        skeleton.setPosition(400, 100);

        AnimationStateData stateData = new AnimationStateData(skeletonData); // Defines mixing (crossfading) between animations.
        stateData.setMix("right", "right", 0.2f);

        state = new AnimationState(stateData); // Holds the animation state for a skeleton (current animation, time, etc).
        state.addAnimation(0, "right", true, 0);            
    }   
}   

Aucun commentaire:

Enregistrer un commentaire