Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#setColor()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Sprite#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpriteAccessor.java    From xibalba with MIT License 6 votes vote down vote up
@Override
public void setValues(Sprite target, int tweenType, float[] newValues) {
  switch (tweenType) {
    case ALPHA:
      target.setAlpha(newValues[0]);
      break;
    case XY:
      target.setPosition(newValues[0], newValues[1]);
      break;
    case COLOR:
      target.setColor(newValues[0], newValues[1], newValues[2], target.getColor().a);
      break;
    case SCALE:
      target.setScale(newValues[0], newValues[1]);
      break;
    default:
      break;
  }
}
 
Example 2
Source File: BlendingSpriteParticleRenderer.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
    int src = canvas.getSrcBlendFunction();
    int dst = canvas.getDstBlendFunction();
    //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD);
    canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD);
    
    Vector2f cameraPos = camera.getRenderPosition(alpha);
    for(int i = 0; i < particles.numberOfAliveParticles; i++) {
        Sprite sprite = particles.sprite[i];
        Vector2f pos = particles.pos[i];
        sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y);
        sprite.setScale(particles.scale[i]);
        sprite.setColor(particles.color[i]);
        sprite.setRotation(particles.rotation[i]);
        canvas.drawRawSprite(sprite);
    }
    
    canvas.setBlendFunction(src, dst);
}
 
Example 3
Source File: Map.java    From xibalba with MIT License 5 votes vote down vote up
private void paintForest() {
  map = new MapCell[width][height];

  Array<String> floorTypes = new Array<>();
  floorTypes.add("0915");
  floorTypes.add("1202");

  for (int x = 0; x < geometry.length; x++) {
    for (int y = 0; y < geometry[x].length; y++) {
      if (geometry[x][y] == MapCell.Type.FLOOR) {
        Sprite floor = Main.asciiAtlas.createSprite(floorTypes.random());
        floor.setColor(Colors.get("forestFloor"));
        floor.setFlip(MathUtils.randomBoolean(), false);

        map[x][y] = new MapCell(
            floor, MapCell.Type.FLOOR, "the forest floor"
        );
      } else {
        Sprite wall = Main.asciiAtlas.createSprite("0" + MathUtils.random(5, 6) + "00");
        Color color = Colors.get("forestTree-" + MathUtils.random(1, 3));
        wall.setColor(color);

        map[x][y] = new MapCell(wall, MapCell.Type.WALL, "a tree");
      }

      map[x][y].sprite.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);
    }
  }

  if (MathUtils.random() > .5f) {
    createWater();
    createBridge();
  }
}
 
Example 4
Source File: Map.java    From xibalba with MIT License 5 votes vote down vote up
private void paintCave() {
  map = new MapCell[width][height];

  for (int x = 0; x < geometry.length; x++) {
    for (int y = 0; y < geometry[x].length; y++) {
      if (geometry[x][y] == MapCell.Type.FLOOR) {
        Sprite floor = Main.asciiAtlas.createSprite("0915");
        Color color = Colors.get("caveFloor-" + +MathUtils.random(1, 3));
        floor.setColor(color);
        map[x][y] = new MapCell(floor, MapCell.Type.FLOOR, "a cave floor");
      } else {
        int neighbours = getGroundNeighbours(x, y);

        if (neighbours > 0) {
          Sprite wall = Main.asciiAtlas.createSprite("1113");
          wall.setColor(Colors.get("caveWall"));
          map[x][y] = new MapCell(wall, MapCell.Type.WALL, "a cave wall");
        } else {
          Sprite nothing = Main.asciiAtlas.createSprite("0000");
          map[x][y] = new MapCell(nothing, MapCell.Type.NOTHING, "nothing");
        }
      }

      map[x][y].sprite.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);
    }
  }

  if (MathUtils.random() > .75f) {
    createWater();
    createBridge();
  }
}
 
Example 5
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite) {
    if(!isBegun) batch.begin();        
    sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example 6
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite, int x, int y, Integer color) {
    if(!isBegun) batch.begin();        
    if(color!=null) {
        Color c = setTempColor(color);
        sprite.setColor(c);            
    } else sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.setPosition(x, y);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example 7
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite, float x, float y, Integer color) {
    if(!isBegun) batch.begin();        
    if(color!=null) {
        Color c = setTempColor(color);
        sprite.setColor(c);            
    } else sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.setPosition(x, y);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example 8
Source File: SpriteParticleRenderer.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {        
    Vector2f cameraPos = camera.getRenderPosition(alpha);
    for(int i = 0; i < particles.numberOfAliveParticles; i++) {
        Sprite sprite = particles.sprite[i];
        Vector2f pos = particles.pos[i];
        sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y);
        sprite.setScale(particles.scale[i]);
        sprite.setColor(particles.color[i]);
        sprite.setRotation(particles.rotation[i]);
        canvas.drawRawSprite(sprite);
    }        
}
 
Example 9
Source File: Map.java    From xibalba with MIT License 4 votes vote down vote up
private void createWater() {
  hasWater = true;
  flooded = new MapCell.Type[width][height];

  for (MapCell.Type[] row : flooded) {
    Arrays.fill(row, MapCell.Type.WALL);
  }

  int floodStartX;
  int floodStartY;

  do {
    floodStartX = MathUtils.random(0, width - 1);
    floodStartY = MathUtils.random(0, height - 1);
  } while (!map[floodStartX][floodStartY].isFloor());

  flood(floodStartX, floodStartY);

  for (int x = 0; x < flooded.length; x++) {
    for (int y = 0; y < flooded[0].length; y++) {
      if (flooded[x][y] == MapCell.Type.FLOOR) {
        Sprite water = Main.asciiAtlas.createSprite("0715");
        water.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);

        MapCell.Type waterType;
        Color lightColor;
        Color darkColor;

        if (getGroundNeighbours(x, y) < 8) {
          waterType = MapCell.Type.SHALLOW_WATER;

          lightColor = Colors.get(
              Objects.equals(type, "forest") ? "waterShallowLightBlue" : "waterShallowLightGreen"
          );

          darkColor = Colors.get(
              Objects.equals(type, "forest") ? "waterShallowDarkBlue" : "waterShallowDarkGreen"
          );
        } else {
          waterType = MapCell.Type.DEEP_WATER;

          lightColor = Colors.get(
              Objects.equals(type, "forest") ? "waterDeepLightBlue" : "waterDeepLightGreen"
          );

          darkColor = Colors.get(
              Objects.equals(type, "forest") ? "waterDeepDarkBlue" : "waterDeepDarkGreen"
          );
        }

        water.setColor(lightColor);
        Tween tween = Tween.to(water, SpriteAccessor.COLOR, .5f).target(
            darkColor.r, darkColor.g, darkColor.b
        ).repeatYoyo(Tween.INFINITY, MathUtils.random());

        map[x][y] = new MapCell(water, waterType, "water", tween);
      }
    }
  }
}
 
Example 10
Source File: MapFire.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Update FIRES.
 *
 * @param delta Time since last frame
 * @param flood Keep spreading?
 */
public void update(float delta, boolean flood) {
  animCounter += delta;

  if (floodedCount < MathUtils.random(100, 300)) {
    if (flood) {
      flood(lastX + MathUtils.random(0, 2), lastY);
      flood(lastX - MathUtils.random(0, 2), lastY);
      flood(lastX, lastY + MathUtils.random(0, 2));
      flood(lastX, lastY - MathUtils.random(0, 2));
    }
  }

  if (animCounter >= .5f) {
    animCounter = 0;

    for (int x = 0; x < flooded.length; x++) {
      for (int y = 0; y < flooded[0].length; y++) {
        if (flooded[x][y] == MapCell.Type.FLOOR) {
          MapCell cell = map.getCellMap()[x][y];
          cell.description = "fire";

          String spriteKey = MathUtils.random() > 0.5 ? "1405" : "1407";
          Sprite sprite = Main.asciiAtlas.createSprite(spriteKey);
          sprite.setColor(Colors.get("fire-" + MathUtils.random(1, 3)));
          cell.sprite.set(sprite);
          cell.sprite.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);

          if (!cell.onFire) {
            ArrayList<Color> fireColors = new ArrayList<>();
            fireColors.add(Colors.get("fire-1"));
            fireColors.add(Colors.get("fire-2"));
            fireColors.add(Colors.get("fire-3"));

            Entity fireLight = new Entity();
            fireLight.add(
                new LightComponent(MathUtils.random(1, 3), true, fireColors)
            );
            fireLight.add(new PositionComponent(x, y));
            WorldManager.world.addEntity(fireLight);
          }

          cell.onFire = true;
        }
      }
    }
  }
}
 
Example 11
Source File: FactorySelector.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
public FactorySelector(Vector2 position, int id) {
	super();
	this.position = position;
	this.setPosition(position.x, position.y);

	switch (id) {
	case 1:
		this.set(Resources.getInstance().factoryP1);
		break;
	case 2:
		this.set(Resources.getInstance().factoryP2);
		break;
	case 3:
		this.set(Resources.getInstance().factoryP3);
		break;
	default:
		this.set(Resources.getInstance().factoryP4);
		break;
	}
	setRotation(90);
	this.setPosition(position.x, position.y);
	this.setColor(0, 0, 0, 1);

	button = new Sprite(Resources.getInstance().aButton);
	button.setPosition(position.x+70f,position.y + 35.f);
	
	aCpuButton = new Sprite(Resources.getInstance().aCpuButton);
	aCpuButton.setPosition(position.x+70f,position.y + 35.f);
	
	aPlayerButton = new Sprite(Resources.getInstance().aPlayerButton);
	aPlayerButton.setPosition(position.x+70f,position.y + 35.f);
	
	cpuButton = new Sprite(Resources.getInstance().cpuButton);
	cpuButton.setPosition(position.x+30f,position.y -0.f);
	
	playerButton = new Sprite(Resources.getInstance().playerButton);
	playerButton.setPosition(position.x+30f,position.y + 70.f);
	
	float pulse = (1 + MathUtils.cos((pulse_time/180.f)*2.f*MathUtils.PI))/2.f;
	float color = fade * pulse + 1 * (1-pulse);
	this.setColor(color, color, color, 1);
	button.setColor(color, color, color, 1);
	cpuButton.setColor(color, color, color, 1);	
}