我想添加一個圖像到android studio的背景,但我不知道如何去做。在下面的代碼中,我有公共靜態最終顏色BACKGROUND_COLOR = Color.WHITE ;,但我想改變它是背景是一個圖像不是顏色。我該怎麼做呢?由於Backgrand image java
package com.udacity.gamedev.icicles;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
public class Constants {
public static final float WORLD_SIZE = 10.0f;
public static final Color BACKGROUND_COLOR = Color.WHITE;
public static final float PLAYER_HEAD_RADIUS = 0.5f;
public static final float PLAYER_HEAD_HEIGHT = 4.0f * PLAYER_HEAD_RADIUS;
public static final float PLAYER_LIMB_WIDTH = 0.1f;
public static final int PLAYER_HEAD_SEGMENTS = 20;
public static final Color PLAYER_COLOR = Color.BLACK;
public static final float PLAYER_MOVEMENT_SPEED = 10.0f;
public static final float ACCELEROMETER_SENSITIVITY = 0.5f;
public static final float GRAVITATIONAL_ACCELERATION = 9.8f;
public static final float ICICLES_HEIGHT = 1.0f;
public static final float ICICLES_WIDTH = 0.5f;
public static final Vector2 ICICLES_ACCELERATION = new Vector2(0, -5.0f);
public static final Color ICICLE_COLOR = Color.WHITE;
public static final float HUD_FONT_REFERENCE_SCREEN_SIZE = 480.0f;
public static final float HUD_MARGIN = 20.0f;
public static final String ASY_LABEL = "Hillary";
public static final String EDIUM_LABEL = "Sanders";
public static final String ARD_LABEL = "Next";
public static final String ONE_LABEL = "Carson";
public static final String EASY_LABEL = "Ted";
public static final String MEDIUM_LABEL = "Rubio";
public static final String HARD_LABEL = "Trump";
public static final String SAM_LABEL = "Next";
public static final float ASY_SPAWNS_PER_SECOND = 10;
public static final float EDIUM_SPAWNS_PER_SECOND = 15;
public static final float ARD_SPAWNS_PER_SECOND = 20;
public static final float ONE_SPAWNS_PER_SECOND = 5;
public static final float EASY_SPAWNS_PER_SECOND = 10;
public static final float MEDIUM_SPAWNS_PER_SECOND = 15;
public static final float HARD_SPAWNS_PER_SECOND = 20;
public static final float SAM_SPAWNS_PER_SECOND = 25;
// TODO: Add constants for the color of each difficulty select circle
public static final Color ASY_COLOR = new Color(0xff0000ff);
public static final Color EDIUM_COLOR = new Color(0xff0000ff);
public static final Color ARD_COLOR = new Color(0, 0, 0, 1);
public static final Color ONE_COLOR = new Color(0, 0, 1, 1);
public static final Color EASY_COLOR = new Color(0, 0, 1, 1);
public static final Color MEDIUM_COLOR = new Color(0, 0, 1, 1);
public static final Color HARD_COLOR = new Color(0, 0, 1, 1);
public static final Color SAM_COLOR = new Color(0, 0, 0, 1);
// TODO: Add constant for the size of the difficulty world
public static final float DIFFICULTY_WORLD_SIZE = 780.0f;
// TODO: Add constant for the radius of the difficulty select "buttons"
public static final float DIFFICULTY_BUBBLE_RADIUS = DIFFICULTY_WORLD_SIZE/12;
// TODO: Add constant for the scale of the difficulty labels (1.5 works well)
public static final float DIFFICULTY_LABEL_SCALE = 1.5f;
// TODO: Add Vector2 constants for the centers of the difficulty select buttons
public static final Vector2 ASY_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/2, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 EDIUM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/3, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 ARD_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/6, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 ONE_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE* 2/3, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 EASY_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/2, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 MEDIUM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/3, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 HARD_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE * 2/3, DIFFICULTY_WORLD_SIZE/2);
public static final Vector2 SAM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/6, DIFFICULTY_WORLD_SIZE/2);
public enum Difficulty {
ASY(ASY_SPAWNS_PER_SECOND, ASY_LABEL),
EDIUM(EDIUM_SPAWNS_PER_SECOND, EDIUM_LABEL),
ARD(ARD_SPAWNS_PER_SECOND, ARD_LABEL),
ONE(ONE_SPAWNS_PER_SECOND, ONE_LABEL),
EASY(EASY_SPAWNS_PER_SECOND, EASY_LABEL),
MEDIUM(MEDIUM_SPAWNS_PER_SECOND, MEDIUM_LABEL),
HARD(HARD_SPAWNS_PER_SECOND, HARD_LABEL),
SAM(SAM_SPAWNS_PER_SECOND, SAM_LABEL);
float spawnRate;
String label;
Difficulty(float spawnRate, String label) {
this.spawnRate = spawnRate;
this.label = label;
}
}
}