Package com.aqpproject.visualisation.gdx

Source Code of com.aqpproject.visualisation.gdx.ActorGDX

/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.visualisation.gdx;

import com.aqpproject.tools.Color;
import com.aqpproject.tools.Vector2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;

/**
* Actor of the scene
*
* @author Alexandre, Clement, Fabrice
*/
public class ActorGDX extends Actor {

    /**
     * Constructor
     *
     * @param name name of the actor
     * @param sprite sprite of the actor
     * @param posX x coordinate
     * @param posY y coordinate
     * @param rotation rotation
     */
    public ActorGDX(String name, SpriteGDX sprite, float posX, float posY, float rotation, int frame, boolean useRealCenter) {
        super(name);
        m_sprite = sprite;
        this.x = posX;
        this.y = posY;
        this.width = sprite.getRegion().getRegionWidth();
        this.height = sprite.getRegion().getRegionHeight();
        this.rotation = rotation;
        m_frame = frame;
        m_teint = new Color(1, 1, 1, 1);
        m_scale = 1.f;
        m_shadowSize = 0;
        m_useRealCenter = useRealCenter;
    }

    public void setFrame(int frame) {
        m_frame = frame;
    }

    public void setAlpha(float alpha) {
        m_teint.a = alpha;
    }

    public void setTeint(Color teint) {
        m_teint = teint;
    }

    public void setScale(float scale) {
        m_scale = scale;
    }

    public void setShadowSize(int size) {
        m_shadowSize = size;
    }

    /**
     * @see Actor#draw(com.badlogic.gdx.graphics.g2d.SpriteBatch, float)
     */
    @Override
    public void draw(SpriteBatch sb, float f) {
        m_sprite.setFrame(m_frame);
        float shiftX = (m_scale - 1) * (m_frame - 1) * width / 2;
        float shiftY = 0;
        Vector2D origin = (m_useRealCenter) ? m_sprite.getRealCenter() : m_sprite.getDefaultCenter();
        if (m_shadowSize > 0) {
            sb.setColor(0, 0, 0, 0.5f);
            sb.draw(m_sprite.getRegion(), x - shiftX + m_shadowSize, y - shiftY - m_shadowSize, origin.x, origin.y, width, height, m_scale, m_scale, rotation);
        }
        sb.setColor(m_teint.r, m_teint.g, m_teint.b, m_teint.a);

        sb.draw(m_sprite.getRegion(), x - shiftX, y - shiftY, origin.x, origin.y, width, height, m_scale, m_scale, rotation);
    }

    /**
     * @see Actor#hit(float, float)
     */
    @Override
    public Actor hit(float f, float f1) {
        return x > 0 && x < width && y > 0 && y < height ? this : null;
    }

    /**
     * @see Actor#touchDown(float, float, int)
     */
    @Override
    public boolean touchDown(float f, float f1, int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * @see Actor#touchUp(float, float, int)
     */
    @Override
    public void touchUp(float f, float f1, int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * @see Actor#touchDragged(float, float, int)
     */
    @Override
    public void touchDragged(float f, float f1, int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    /////////////////////////////////////////
    // Attributes
    /////////////////////////////////////////
    private SpriteGDX m_sprite;
    private int m_frame;
    private Color m_teint;
    private float m_scale;
    private int m_shadowSize;
    private boolean m_useRealCenter;
}
TOP

Related Classes of com.aqpproject.visualisation.gdx.ActorGDX

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.