/*******************************************************************************
* Copyright 2012-Present, MoribitoTech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.moribitotech.mtx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.moribitotech.mtx.settings.AppSettings;
public abstract class AbstractGroupLight extends Group {
//
protected final String logTag = "MtxActorLog";
public static boolean logActive = true;
// Texture Region for actor (Not mandatory)
private TextureRegion textureRegion;
private boolean isTextureRegionActive = false;
public AbstractGroupLight(TextureRegion textureRegion, boolean isTextureRegionActive, float posX, float posY, float orgnX, float orgnY, float width, float height){
super();
this.textureRegion = textureRegion;
this.isTextureRegionActive = isTextureRegionActive;
setBounds(posX, posY, width, height);
setPosition(posX, posY);
setSize(width, height);
setOrigin(orgnX, orgnY);
}
public AbstractGroupLight(TextureRegion textureRegion, boolean isTextureRegionActive, float posX, float posY, float width, float height){
super();
this.textureRegion = textureRegion;
this.isTextureRegionActive = isTextureRegionActive;
setBounds(posX, posY, width, height);
setPosition(posX, posY);
setSize(width, height);
}
public AbstractGroupLight(float posX, float posY, float width, float height){
super();
setBounds(posX, posY, width, height);
setPosition(posX, posY);
setSize(width, height);
}
public AbstractGroupLight(float width, float height, boolean DIPActive){
super();
if(DIPActive){
float ratioSize = AppSettings.getWorldSizeRatio();
//
setSize(width * ratioSize, height * ratioSize);
} else{
setSize(width, height);
}
}
public AbstractGroupLight(){
super();
}
@Override
public void draw(SpriteBatch batch, float parentAlpha){
super.draw(batch, parentAlpha);
// For fade out/in effect
batch.setColor(this.getColor());
// DRAW TEXTURE REGION (Draw only if set active and not null)
// ##################################################################
if(isTextureRegionActive && textureRegion != null){
// Draw it due to actors' settings
batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(),
getRotation());
}
}
/**
* Translate actor in a direction of speed without stopping. Actor moves
* in constants speed set without acceleration
*
* @param speedX axis-X speed
* @param speedY axis-Y speed
* @param delta the delta time for accurate speed
* */
public void translateWithoutAcc(float speedX, float speedY, float delta){
setPosition(getX() + (speedX * delta), getY() + (speedY * delta));
}
/**
* Get textureRegion of the actor
*
* @return TextureRegion
*
* */
public TextureRegion getTextureRegion() {
return textureRegion;
}
/**
* Set texture region for the actor, it will be drawn only if texture region is set and active
*
* @param textureRegion texture region of the actor
* @param isTextureRegionActive set texture region active to be drawn or not
* */
public void setTextureRegion(TextureRegion textureRegion, boolean isTextureRegionActive) {
this.textureRegion = textureRegion;
this.isTextureRegionActive = isTextureRegionActive;
}
}