- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在互联网上搜索并搜索如何在 LibGDX(此处和其他网站)中正确调整大小之后,我的 Tic tac Toe 游戏遇到了一个大问题。当切换屏幕时,我的 FitViewport 不会按预期调整大小。我确实使用 VLC Media Player 制作了两个视频来解释我的问题。
这是第一个。这表明调整窗口大小时一切正常。
这里显示了我的问题。
我不知道我的问题是否是当使用我的ScreenManager创建新屏幕时,我没有在新实例化的屏幕上调用resize
。如果是这样,那么我想知道该怎么做。
主类
public class TicTacToeGame extends ApplicationAdapter {
private TicTacToeScreenManager screenManager;
public static final int WINDOW_WIDTH = 900;
public static final int WINDOW_HEIGHT = 1200;
public SpriteBatch batch;
@Override
public void create () {
screenManager = new TicTacToeScreenManager();
//index
screenManager.AddScreen(HomeScreen.class); // 0
screenManager.AddScreen(SettingsScreen.class); // 1
screenManager.AddScreen(GameScreen.class); // 2
screenManager.AddScreen(GameOverScreen.class); // 3
screenManager.AddScreen(CreditsScreen.class); // 4
batch = new SpriteBatch();
}
@Override
public void resize (int width, int height) {
if(screenManager.getCurrentScreen() != null)
{
screenManager.getCurrentScreen().resize(width, height);
}
}
@Override
public void render () {
screenManager.render(batch);
}
@Override
public void pause () {
}
@Override
public void resume () {
}
@Override
public void dispose () {
batch.dispose();
}
}
渲染屏幕
public abstract class RenderingScreen implements InputProcessor, Disposable{
protected OrthographicCamera camera;
protected Vector3 mouse;
protected Viewport viewport;
protected Stage stage;
protected TicTacToeScreenManager screenManager;
/**
* Default Constructor.
*/
public RenderingScreen(TicTacToeScreenManager screenManager)
{
this.screenManager = screenManager;
camera = new OrthographicCamera();
camera.position.set(480, 640, 0);
viewport = new FitViewport(TicTacToeGame.WINDOW_WIDTH, TicTacToeGame.WINDOW_HEIGHT, camera);
mouse = new Vector3();
stage = new Stage(viewport);
Gdx.input.setInputProcessor(stage);
}
/**
* Initialize images, stage, skin, etc.
*/
public abstract void onInit();
public abstract void drawGraphicRender(SpriteBatch batch);
public void resize(int width, int height)
{
viewport.update(width, height);
stage.getViewport().update(width, height, true);
camera.update();
}
/**
* Release what we have used
*/
@Override
public void dispose() {
}
/**
* Clear the screen.
*/
public void clearScreen()
{
Gdx.gl.glClearColor( 0, 0, 0, 1 );
Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT );
}
/** Called when a key was pressed
*
* @param keycode one of the constants in {@link Input.Keys}
* @return whether the input was processed */
public boolean keyDown (int keycode)
{
return false;
}
/** Called when a key was released
*
* @param keycode one of the constants in {@link Input.Keys}
* @return whether the input was processed */
public boolean keyUp (int keycode)
{
return false;
}
/** Called when a key was typed
*
* @param character The character
* @return whether the input was processed */
public boolean keyTyped (char character)
{
return false;
}
/** Called when the screen was touched or a mouse button was pressed. The button parameter will be {@link Buttons#LEFT} on iOS.
* @param screenX The x coordinate, origin is in the upper left corner
* @param screenY The y coordinate, origin is in the upper left corner
* @param pointer the pointer for the event.
* @param button the button
* @return whether the input was processed */
public boolean touchDown (int screenX, int screenY, int pointer, int button)
{
return false;
}
/** Called when a finger was lifted or a mouse button was released. The button parameter will be {@link Buttons#LEFT} on iOS.
* @param pointer the pointer for the event.
* @param button the button
* @return whether the input was processed */
public boolean touchUp (int screenX, int screenY, int pointer, int button)
{
return false;
}
/** Called when a finger or the mouse was dragged.
* @param pointer the pointer for the event.
* @return whether the input was processed */
public boolean touchDragged (int screenX, int screenY, int pointer)
{
return false;
}
/** Called when the mouse was moved without any buttons being pressed. Will not be called on iOS.
* @return whether the input was processed */
public boolean mouseMoved (int screenX, int screenY)
{
return false;
}
/** Called when the mouse wheel was scrolled. Will not be called on iOS.
* @param amount the scroll amount, -1 or 1 depending on the direction the wheel was scrolled.
* @return whether the input was processed. */
public boolean scrolled (int amount)
{
return false;
}
final public void render(SpriteBatch batch) {
drawGraphicRender(batch);
}
}
屏幕管理器
public class TicTacToeScreenManager {
@SuppressWarnings("rawtypes")
private ArrayList<Class> screens = new ArrayList<Class>();
private int activeScreen;
private RenderingScreen currScreen, nextScreen;
//transition style
public enum Transition_Style
{
SMOOTH, SLICE, SLIDE;
}
private Transition_Style transition_Style;
//handling transitions
private FrameBuffer currFbo, nextFbo;
private SpriteBatch batch;
private float transitionDuration;
private ScreenTransition screenTransition;
private boolean transitionRunning;
private int nextScreenIdx = -1;
//create an instance..
private RenderingScreen createInstance(Class<? extends RenderingScreen> screen) {
try {
Constructor constr = ClassReflection.getDeclaredConstructor(screen, this.getClass());
RenderingScreen renderingScreen = (RenderingScreen) constr.newInstance(this);
renderingScreen.onInit();
return renderingScreen;
} catch (ReflectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* Render the current screen to the GdxGraphics
* @param g The instance of GdxGraphics to draw on
*/
public void render(SpriteBatch b) {
// Normal case, no transition
if (!transitionRunning) {
currScreen.render(b);
}else {
// Called at the beginning of the transition
if (screenTransition == null) {
int w = Gdx.graphics.getWidth();
int h = Gdx.graphics.getHeight();
this.currFbo = new FrameBuffer(Pixmap.Format.RGB888, w, h, false);
this.nextFbo = new FrameBuffer(Pixmap.Format.RGB888, w, h, false);
batch = new SpriteBatch();
switch(transition_Style){
case SLICE:
screenTransition = new SliceTransition(1.15f, Directions.UP_DOWN, 12, Interpolation.pow4Out);
break;
case SMOOTH:
screenTransition = new AlphaFadingTransition(1.5f);
break;
case SLIDE:
screenTransition = new SlideTransition(0.75f, Direction.LEFT, Interpolation.circleIn, true);
break;
}
// Render current screen to FBO
currFbo.begin();
currScreen.render(b);
currFbo.end();
// Releasing resources from the current screen
currScreen.dispose();
currScreen = null;
nextScreen = createInstance(screens.get(getNextScreenIndex()));
// Render next screen to FBO
nextFbo.begin();
nextScreen.render(b);
nextFbo.end();
}
// Do the transition
transition(Gdx.graphics.getDeltaTime());
}
}
/**
* Do the actual transition between the screens
* @param deltaTime
*/
private void transition(float deltaTime) {
float duration = screenTransition.getDuration();
// Update the progress of ongoing transition
transitionDuration = Math.min(transitionDuration + deltaTime, duration);
// When transition is over
if (screenTransition == null || transitionDuration >= duration) {
screenTransition = null;
transitionRunning = false;
activeScreen = getNextScreenIndex();
currScreen = nextScreen;
nextScreen = null;
transitionDuration = 0;
return;
}
// Render the transition effect to screen
float alpha = transitionDuration / duration;
screenTransition.render(batch,
currFbo.getColorBufferTexture(),
nextFbo.getColorBufferTexture(),
alpha);
}
// Go to the next screen if no target index has been choose
private int getNextScreenIndex() {
if (nextScreenIdx < 0)
return (activeScreen + 1) % screens.size();
return nextScreenIdx;
}
// Check if the screen index is out of bound or not
private int checkIndexBounds(int screenIndex) {
if (screenIndex < 0)
return 0;
if (screenIndex > screens.size() - 1)
return screens.size() - 1;
return screenIndex;
}
/**
* Add a screen to the screen list
*
* @param screen The class of the screen to add (we only want classes whose the super-class is RenderingScreen)
*/
public void AddScreen(Class<? extends RenderingScreen> screen){
screens.add(screen);
if (currScreen == null) {
currScreen = createInstance(screens.get(0));
}
}
/**
* Called to transition to the next screen with slicing
*/
public void sliceTransitionToNext(int index) {
if (activeScreen == index)
return;
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(index);
transitionRunning = true;
transition_Style = Transition_Style.SLICE;
}
}
/**
* Called to transition to the next screen with fade-out
*/
public void smoothTransitionToNext(int index) {
if (activeScreen == index)
return;
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(index);
transitionRunning = true;
transition_Style = Transition_Style.SMOOTH;
}
}
/**
* Called to transition to the next screen with sliding
*/
public void SlideTransitionToNext(int index)
{
if (activeScreen == index)
return;
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(index);
transitionRunning = true;
transition_Style = Transition_Style.SLIDE;
}
}
/**
* @return The active screen which is currently rendered
*/
public RenderingScreen getCurrentScreen() {
return !transitionRunning ? currScreen : null;
}
}
设置屏幕
public class SettingsScreen extends RenderingScreen{
public enum ComputerLevel
{
EASY, MEDIUM, ADVANCED;
}
public static ComputerLevel level;
private GameComponent compo;
private Skin skin, skin1, holo;
private boolean nameOk;
private boolean opponentOk;
public static boolean MusicIsPlaying = true;
private TextField name;
private TextField opponent;
private TextFieldStyle textStyle;
private Texture textOk;
private Texture textFalse;
private Texture piece1, piece2, piece3;
private Texture ORIGINAL_X, ORIGINAL_O;
private Texture bgWhite;
private Image cross, circle, cross1, circle1;
private Image piecechoice1, piecechoice2, piecechoice3;
private BitmapFont fontmode;
private BitmapFont lovinn, lovinn1, lovinn2;
private TextButton back;
private TextButton start;
private TextButton SoundOn, SoundOff;
private TextButtonStyle buttonStyle;
private TextButton easy, medium, hard;
//static final attributes
private static final int SPACE_TEXTFIELD = 120;
private static final int WIDTH = 100;
private static final int SPACE = 120;
private static final int HEIGHT = 75;
//By default the name of player will be exactly Player1, Player2.
public static String playerName1 = "Player1";
public static String playerName2 = "Player2";
public static int firstplayer = 0;
public static int PIECES_CHOICES = 0;
public static int compLevel = 0;
private float scale, posY, posSymbol;
private LabelStyle labStyle;
private Dialog error;
private String stringError;
private boolean OK;
public SettingsScreen(TicTacToeScreenManager screenManager) {
super(screenManager);
}
@Override
public void onInit() {
compo = new GameComponent();
//Skin
skin = new Skin(Gdx.files.internal("skin/comic-ui.json"));
skin.add("bg", new Texture("images/textfieldbg.png"));
skin.add("cursor", new Texture("images/cursor.png"));
skin1 = new Skin(Gdx.files.internal("skin/comic-ui.json"));
holo = new Skin(Gdx.files.internal("skin/uiskin.json"));
textOk = new Texture("images/true.png");
textFalse = new Texture("images/false.png");
ORIGINAL_X = new Texture("images/cross.png");
ORIGINAL_O = new Texture("images/circle.png");
piece1 = new Texture("images/first.png");
piece2 = new Texture("images/second.png");
piece3 = new Texture("images/third.png");
bgWhite = new Texture("images/white.png");
fontmode = new BitmapFont(Gdx.files.internal("fonts/brushstroke.fnt"), Gdx.files.internal("fonts/brushstroke.png"), false);
lovinn = new BitmapFont(Gdx.files.internal("fonts/Lovinn.fnt"), Gdx.files.internal("fonts/Lovinn.png"), false);
lovinn1 = new BitmapFont(Gdx.files.internal("fonts/Lovinn.fnt"), Gdx.files.internal("fonts/Lovinn.png"), false);
lovinn2 = new BitmapFont(Gdx.files.internal("fonts/Lovinn.fnt"), Gdx.files.internal("fonts/Lovinn.png"), false);
fontmode.getData().setScale(.93f);
lovinn.getData().setScale(1.5f);
lovinn1.getData().setScale(.83f);
labStyle = new LabelStyle();
labStyle.font = lovinn2;
labStyle.fontColor = Color.BLACK;
//TextField and TextFieldStyle.
textStyle = new TextFieldStyle();
textStyle.font = lovinn1;
textStyle.background = skin.getDrawable("bg");
textStyle.cursor = skin.getDrawable("cursor");
textStyle.fontColor = Color.BLACK;
name = new TextField("Player1", textStyle);
name.setWidth(320);
name.setPosition(compo.chalkboard.getWidth() / 1.8f, compo.chalkboard.getHeight() - SPACE_TEXTFIELD);
name.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char key)
{
//When we pressed ENTER, do something!(for desktop or android ENTER)
if(key == 13 || key == 10)
{
if(name.getText().isEmpty())
{
nameOk = false;
}else {
nameOk = true;
playerName1 = name.getText();
}
}
}
});
opponent = new TextField("Player2", textStyle);
opponent.setWidth(320);
opponent.setPosition(name.getX(), name.getY() - SPACE_TEXTFIELD);
opponent.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char key)
{
//When we pressed ENTER, do something!
if(key == 13)
{
Gdx.input.setOnscreenKeyboardVisible(true);
if(opponent.getText().isEmpty())
{
opponentOk = false;
}else {
opponentOk = true;
playerName2 = opponent.getText();
}
}
}
});
//Handling computer level
easy = new TextButton("Easy", skin);
easy.setSize(WIDTH, HEIGHT);
easy.setPosition(name.getX(), opponent.getY() - 90);
easy.setColor(Color.WHITE);
easy.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
level = ComputerLevel.EASY;
compLevel = 1;
easy.setColor(Color.GREEN);
medium.setColor(Color.WHITE);
hard.setColor(Color.WHITE);
}
});
medium = new TextButton("Med", skin);
medium.setSize(WIDTH, HEIGHT);
medium.setPosition(easy.getX() + SPACE, easy.getY());
medium.setColor(Color.WHITE);
medium.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
level = ComputerLevel.MEDIUM;
compLevel = 2;
medium.setColor(Color.YELLOW);
hard.setColor(Color.WHITE);
easy.setColor(Color.WHITE);
}
});
hard = new TextButton("Hard", skin1);
hard.setSize(WIDTH, HEIGHT);
hard.setPosition(medium.getX() + SPACE, medium.getY());
hard.setColor(Color.WHITE);
hard.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
level = ComputerLevel.ADVANCED;
compLevel = 3;
hard.setColor(Color.CORAL);
easy.setColor(Color.WHITE);
medium.setColor(Color.WHITE);
}
});
cross = new Image( ORIGINAL_X);
cross.setPosition(compo.chalkboard.getWidth() / 6f, name.getY() + 16);
cross.setScale(.4f, .4f);
circle = new Image(ORIGINAL_O);
circle.setPosition(cross.getX(), opponent.getY() + 16);
circle.setScale(.4f, .4f);
if(HomeScreen.MODE == 1)
{
scale = .5f;
}else {
scale = .4f;
}
if(HomeScreen.MODE == 1)
{
posSymbol = SPACE + HEIGHT;
}else {
posSymbol = SPACE + HEIGHT + 50;
}
cross1 = new Image( ORIGINAL_X);
cross1.setScale(.45f, .45f);
cross1.setPosition(name.getX() + 100, compo.chalkboard.getY() + posSymbol);
cross1.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
firstplayer = 1;
cross1.setColor(Color.RED);
circle1.setColor(Color.WHITE);
}
});
circle1 = new Image(ORIGINAL_O);
circle1.setScale(.45f, .45f);
circle1.setPosition(name.getX() + 250, compo.chalkboard.getY() + posSymbol);
circle1.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
firstplayer = 2;
circle1.setColor(Color.YELLOW);
cross1.setColor(Color.WHITE);
}
});
if(HomeScreen.MODE == 1)
{
posY = 110;
}else {
posY = 150;
}
//Piece Choices
piecechoice1 = new Image(piece1);
piecechoice1.setPosition(cross1.getX() - 160, cross1.getY() - posY);
piecechoice1.setSize(120, 60);
piecechoice1.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
PIECES_CHOICES = 1;
}
});
piecechoice2 = new Image(piece2);
piecechoice2.setPosition(piecechoice1.getX() + 150, cross1.getY() - posY);
piecechoice2.setSize(120, 60);
piecechoice2.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
PIECES_CHOICES = 2;
}
});
piecechoice3 = new Image(piece3);
piecechoice3.setPosition(piecechoice2.getX() + 150, cross1.getY() - posY);
piecechoice3.setSize(120, 60);
piecechoice3.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
PIECES_CHOICES = 3;
}
});
//button back and start
buttonStyle = new TextButtonStyle();
buttonStyle.font = lovinn;
buttonStyle.fontColor = Color.valueOf("65390C");
back = new TextButton("back", buttonStyle);
back.setPosition(compo.smallboard.getImageX(), compo.smallboard.getY() - 15);
back.addCaptureListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
screenManager.SlideTransitionToNext(0);
}
});
start = new TextButton("start", buttonStyle);
start.setPosition(compo.smallboard.getImageX() + Gdx.graphics.getWidth() + 200, compo.smallboard.getY() - 10);
start.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if(NoErrors()){
screenManager.sliceTransitionToNext(2);
}
}
});
//Button on/off for options
SoundOn = new TextButton("On", skin);
SoundOn.setPosition(name.getX(), name.getY());
SoundOn.setSize(WIDTH, HEIGHT);
SoundOn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
MusicGame.MenuLoop.play();
MusicIsPlaying = true;//A static boolean for the HomeScreen
}
});
SoundOff = new TextButton("Off", skin);
SoundOff.setPosition(SoundOn.getX() + 200, SoundOn.getY());
SoundOff.setSize(WIDTH, HEIGHT);
SoundOff.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if(MusicGame.MenuLoop.isPlaying())
{
MusicGame.MenuLoop.stop();
MusicIsPlaying = false;//A static boolean for the HomeScreen
}
}
});
compo.getActor(stage);
switch(HomeScreen.MODE)
{
case 1:
stage.addActor(easy);
stage.addActor(medium);
stage.addActor(hard);
stage.addActor(name);
stage.addActor(opponent);
stage.addActor(start);
stage.addActor(cross);
stage.addActor(circle);
stage.addActor(cross1);
stage.addActor(circle1);
stage.addActor(piecechoice1);
stage.addActor(piecechoice2);
stage.addActor(piecechoice3);
break;
case 2:
stage.addActor(name);
stage.addActor(opponent);
stage.addActor(start);
stage.addActor(cross);
stage.addActor(circle);
stage.addActor(cross1);
stage.addActor(circle1);
stage.addActor(piecechoice1);
stage.addActor(piecechoice2);
stage.addActor(piecechoice3);
break;
case 3:
stage.addActor(SoundOn);
stage.addActor(SoundOff);
break;
default:
break;
}
stage.addActor(back);
}
private boolean NoErrors()
{
switch(HomeScreen.MODE)
{
case 1:
if(firstplayer <= 0){
stringError = "Who's the first player?";
error = new Dialog("WARNING !", holo);
error.text(stringError, labStyle);
error.button("OK", true);
error.setResizable(false);
error.show(stage);
}else if(PIECES_CHOICES == 0){
stringError = "What is your piece ?";
error = new Dialog("WARNING !", holo);
error.text(stringError, labStyle);
error.button("OK", true);
error.setResizable(false);
error.show(stage);
}else if(compLevel == 0)
{
stringError = "What is Computer's Level?";
error = new Dialog("WARNING !", holo);
error.text(stringError, labStyle);
error.button("OK", true);
error.setResizable(false);
error.show(stage);
}else {
OK = true;
}
break;
case 2:
if(firstplayer <= 0)
{
stringError = "Who's the first player?";
error = new Dialog("WARNING !", holo);
error.text(stringError, labStyle);
error.button("OK");
error.setResizable(false);
error.show(stage);
}else {
OK = true;
}
break;
}
return OK;
}
public static ComputerLevel getLevel()
{
return level;
}
private final void drawModes(SpriteBatch batch)
{
if(HomeScreen.MODE == 1 || HomeScreen.MODE == 2)
{
if(nameOk)
{
batch.draw(textOk, compo.chalkboard.getWidth() + 17, name.getY() + 10, 50, 50);
}else {
batch.draw(textFalse, compo.chalkboard.getWidth() + 17, name.getY() + 10, 50, 50);
}
if(opponentOk)
{
batch.draw(textOk, compo.chalkboard.getWidth() + 17, opponent.getY() + 10, 50, 50);
}else {
batch.draw(textFalse, compo.chalkboard.getWidth() + 17, opponent.getY() + 10, 50, 50);
}
switch(PIECES_CHOICES)
{
case 1:
batch.draw(bgWhite, piecechoice1.getX() - 15, piecechoice1.getY() - piece1.getHeight() / 9, 150, piece1.getHeight() / 2);
break;
case 2:
batch.draw(bgWhite, piecechoice2.getX() - 15, piecechoice3.getY() - piece2.getHeight() / 9, 150, piece2.getHeight() / 2);
break;
case 3:
batch.draw(bgWhite, piecechoice3.getX() - 15, piecechoice3.getY() - piece3.getHeight() / 9, 150, piece3.getHeight() / 2);
break;
default:
break;
}
}
switch(HomeScreen.MODE)
{
case 1:
fontmode.draw(batch, "Player vs Computer", compo.chalkboard.getWidth() / 5.5f, compo.chalkboard.getHeight() * 1.12f);
lovinn1.setColor(Color.LIGHT_GRAY);
lovinn1.draw(batch, "Player", compo.chalkboard.getWidth() / 3.8f, name.getY() + 68);
lovinn1.draw(batch, "Computer", compo.chalkboard.getWidth() / 3.8f, opponent.getY() + 68);
lovinn1.setColor(Color.WHITE);
lovinn1.draw(batch, "First Player", compo.chalkboard.getWidth() / 5, cross1.getY() + 60);
lovinn1.draw(batch, "Pieces", compo.chalkboard.getWidth() / 5, piecechoice1.getY() + 60);
break;
case 2:
fontmode.draw(batch, "Player vs Player", compo.chalkboard.getWidth() / 4.3f, compo.chalkboard.getHeight() * 1.12f);
lovinn1.setColor(Color.LIGHT_GRAY);
lovinn1.draw(batch, "Player 1", compo.chalkboard.getWidth() / 3.8f, name.getY() + 68);
lovinn1.draw(batch, "Player 2", compo.chalkboard.getWidth() / 3.8f, opponent.getY() + 68);
lovinn1.setColor(Color.WHITE);
lovinn1.draw(batch, "First Player", compo.chalkboard.getWidth() / 5, cross1.getY() + 60);
lovinn1.draw(batch, "Pieces", compo.chalkboard.getWidth() / 5, piecechoice1.getY() + 60);
break;
case 3:
fontmode.draw(batch, "Options", compo.chalkboard.getWidth() / 2 - 50, compo.chalkboard.getHeight() * 1.12f);
lovinn1.setColor(Color.LIGHT_GRAY);
lovinn1.draw(batch, "Sound", cross.getX() + 30, SoundOn.getY() + 60);
break;
}
}
@Override
public void drawGraphicRender(SpriteBatch batch) {
batch.setProjectionMatrix(camera.combined);
camera.update();
clearScreen();
stage.act(Gdx.graphics.getDeltaTime());
viewport.apply();
stage.draw();
batch.begin();
drawModes(batch);
batch.end();
}
/**
* Release what we have used
*/
@Override
public void dispose() {
skin.dispose();
skin1.dispose();
holo.dispose();
stage.dispose();
textOk.dispose();
textFalse.dispose();
ORIGINAL_O.dispose();
ORIGINAL_X.dispose();
lovinn.dispose();
lovinn1.dispose();
lovinn2.dispose();
bgWhite.dispose();
piece1.dispose();
piece2.dispose();
piece3.dispose();
fontmode.dispose();
}
}
最佳答案
所以,在彻底检查了我的代码之后,我终于想出了一个适合我的游戏的计划。所以真正的问题出在我的 TicTacToeScreenManager 类 内部。
这是我的 ScreenManager,现在进行了适当的修改:
public class TicTacToeScreenManager {
private ArrayList<Class<? extends RenderingScreen>> screens = new ArrayList<Class<? extends RenderingScreen>>();
private int activeScreen;
private RenderingScreen currScreen, nextScreen, renderingScreen;
//transition style
public enum Transition_Style
{
SMOOTH, SLICE, SLIDE;
}
private Transition_Style transition_Style;
//handling transitions
private FrameBuffer currFbo, nextFbo;
private SpriteBatch batch = new SpriteBatch();;
private float transitionDuration;
private ScreenTransition screenTransition;
private boolean transitionRunning;
private int nextScreenIdx = -1;
/**
* Create an instance of RenderingScreen's class.
*
* @param screen the RenderingScreen's child class.
* @return
*/
private RenderingScreen createInstance(Class<? extends RenderingScreen> screen) {
try {
Constructor constr = ClassReflection.getDeclaredConstructor(screen, this.getClass());
renderingScreen = (RenderingScreen) constr.newInstance(this);
renderingScreen.Init();
} catch (ReflectionException e) {
e.printStackTrace();
}
return renderingScreen;
}
/**
* Render the current screen to the GdxGraphics
*/
public void render() {
float deltaTime = Gdx.graphics.getDeltaTime();
// Normal case, no transition
if(!transitionRunning) {
currScreen.render(batch);
}else {
// Called at the beginning of the transition
if (screenTransition == null) {
int w = TicTacToeGame.WINDOW_WIDTH;
int h = TicTacToeGame.WINDOW_HEIGHT;
this.currFbo = new FrameBuffer(Pixmap.Format.RGB888, w, h, false);
this.nextFbo = new FrameBuffer(Pixmap.Format.RGB888, w, h, false);
switch(transition_Style){
case SLICE:
screenTransition = new SliceTransition(1.15f, Directions.UP_DOWN, 12, Interpolation.pow4Out);
break;
case SMOOTH:
screenTransition = new AlphaFadingTransition(1.5f);
break;
case SLIDE:
screenTransition = new SlideTransition(0.75f, Direction.LEFT, Interpolation.circleIn, true);
break;
}
currFbo.begin();
currScreen.resize(w, h);//before drawing the current screen we must resize!!!!
currScreen.render(batch);
currFbo.end();
// Releasing resources from the current screen
currScreen.dispose();
currScreen = null;
//create the instance of the next screen
nextScreen = createInstance(screens.get(getNextScreenIndex()));
// Render next screen to FBO
nextFbo.begin();
nextScreen.resize(w, h);//before drawing the next screen we also must resize!!!!
nextScreen.render(batch);
nextFbo.end();
}
//Now, before we do the transition we have to resize the whole screen again!!!
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//do the transition.
setTransition(deltaTime);
}
}
/**
* This function will resize the whole screen before drawing the transition between two screens.
*
* @param width the screen width.
* @param height the screen height.
*/
public void resize(int width, int height) {
if (currScreen != null) {
currScreen.resize(width, height);
}
if(nextScreen != null) {
nextScreen.resize(width, height);
}
}
/**
* Do the actual transition between the screens
* @param deltaTime
*/
private void setTransition(float deltaTime) {
float duration = screenTransition.getDuration();
// Update the progress of ongoing transition
transitionDuration = Math.min(transitionDuration + deltaTime, duration);
// When transition is over
if (transitionDuration >= duration) {
screenTransition = null;
transitionRunning = false;
currScreen = nextScreen;
nextScreen = null;
transitionDuration = 0;
return;
}
// Render the transition effect to screen
float alpha = transitionDuration / duration;
screenTransition.render(batch,
currFbo.getColorBufferTexture(),
nextFbo.getColorBufferTexture(),
alpha);
}
/**
* Go to the next screen if no target index has been choose.
* @return
*/
private int getNextScreenIndex() {
if (nextScreenIdx < 0) {
return (activeScreen + 1) % screens.size();
}
return nextScreenIdx;
}
/**
* Check if the screen index is out of bound or not
* @param screenIndex
* @return
*/
private int checkIndexBounds(int screenIndex) {
if (screenIndex < 0) {
return 0;
}else if (screenIndex > screens.size() - 1) {
return screens.size() - 1;
}else {
return screenIndex;
}
}
/**
* Add a screen to the screen list
*
* @param screen The class of the screen to add (we only want classes whose the super-class is RenderingScreen)
*/
public void AddScreen(Class<? extends RenderingScreen> screen){
screens.add(screen);
if (currScreen == null) {
currScreen = createInstance(screens.get(0));
}
}
/**
* Called to activate the next screen without any transition
* @param nextScreen the index of the nextScreen. (See in the class in TicTacToeGame.)
*/
public void NoTransitionToNext(int nextScreen){
if(!transitionRunning){
currScreen.dispose();
nextScreenIdx = -1;
activeScreen = checkIndexBounds(nextScreen);
currScreen = createInstance(screens.get(activeScreen));
}
}
/**
* Called to transition to the next screen with slicing
*/
public void sliceTransitionToNext(int nextScreen) {
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(nextScreen);
transitionRunning = true;
transition_Style = Transition_Style.SLICE;
}
}
/**
* Called to transition to the next screen with fade-out
*/
public void smoothTransitionToNext(int nextScreen) {
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(nextScreen);
transitionRunning = true;
transition_Style = Transition_Style.SMOOTH;
}
}
/**
* Called to transition to the next screen with sliding
*/
public void SlideTransitionToNext(int nextScreen)
{
if (!transitionRunning) {
nextScreenIdx = checkIndexBounds(nextScreen);
transitionRunning = true;
transition_Style = Transition_Style.SLIDE;
}
}
/**
* Get the current screen which is not transitioning.
*
* @return The active screen which is currently rendered
*/
public RenderingScreen getCurrentScreen() {
return !transitionRunning ? currScreen : null;
}
}
所以问题是,在渲染当前屏幕、下一个屏幕和过渡之前,我没有调用resize
函数。为了解决这个问题,我只需在“绘制”当前和下一个屏幕以及过渡效果之前调整大小。
现在这是我的想法的结果:https://youtu.be/46Pd4cWkroU
我没有真正意识到的另一个问题是与虚拟(宽度、高度)和 Gdx 图形(宽度、高度)混合。
现在一切都像魅力一样!!
关于java - 我的 FitViewport 不适用于所有屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070949/
我最近为我的一个 iPhone 应用程序上传了更新,现在该应用程序刚刚准备好销售,但我只更新 iPhone 6 的屏幕截图,而不更新其他屏幕截图。现在我明白了,它们是新游戏的旧屏幕,这可能会让用户感到
我需要清除 Scala 中的控制台屏幕 我尝试过标准 ANSI Clear 屏幕,rosettacode.org 建议将其称为“终端控制/清除屏幕”here object Cls extends Ap
我需要清除 Scala 中的控制台屏幕 我尝试过标准 ANSI Clear 屏幕,rosettacode.org 建议将其称为“终端控制/清除屏幕”here object Cls extends Ap
我将从头开始,我正在开发一个跨越多个监视器的应用程序,每个监视器将包含一个 WPF 窗口,并且这些窗口使用一个 View 模型类进行控制。现在假设我在 200,300 (x,y) 处的所有窗口上都有一
谁能告诉我如何阻止矩形在我的游戏中离开面板(屏幕)?矩形随着击键并排移动。 最佳答案 这是你应该做的: 1. 跟踪矩形的 (x,y) 坐标。 2. 确保矩形的x + width 不大于JPanel 的
我正在尝试检测电源按钮是否在 4 秒内被按下 3 次。以下代码无效。 public class PowerButtonReceiver extends BroadcastReceiver{ s
我为我的新网上商店制作了一个横幅,但有一个问题。例如,当网站在我的笔记本电脑上显示为全尺寸时,横幅非常适合,但是当我在移动设备、笔记本电脑和较小尺寸的网站上看到该网站时,横幅就不合适了。我真的希望你们
我希望这个问题能够得到解决: 给定,屏幕 session 正在运行,并在终端中打开(附加)。 问题。 如果终端 session 终止,但未与屏幕 session 分离,则屏幕 session 中运行的
如何在点击通知时转到特定屏幕?我在 javascript 中使用了云功能,当我点击通知时,它打开了我的应用程序而不是特定的屏幕 _fcm.configure( onMessage: (Map m
Qt 确实支持像素比率 (devicePixelRatio),这在我的各种桌面上是不同的: ) 桌面 w1920 h1080 - 比例:1 ) 桌面 w3840 h2160 与 qputenv("QT
我一直在做一些研究,发现了这种情况。如果要写入STDOUT(屏幕),将无法执行多线程脚本,该脚本通过简单的单线程脚本可以更快地打印数据。但是,如果您写入这样的文件: myPrinter.perl >
我是 ABAP 的新手,我想制作一个具有多个屏幕和一个初始主屏幕的程序,可以在其中看到所有程序屏幕的列表。我知道我可以对它们进行硬编码,但应该有更好的方法。 如果有任何类型的字段/区域,我需要使此列表
我目前正在探索创建越狱调整。我想解锁手机屏幕。这是怎么做到的?在 iOS 7 上可以使用哪些私有(private) API 来实现这一点? 最佳答案 如果我们谈论越狱,那么您可以编写一个 Spring
我正在寻找一种方法来关闭 iPhone 屏幕而不让 iPhone 进入休眠状态。我真的不介意关闭屏幕是否违反苹果规则。将窗口 alpha 设置为 0 可以解决问题吗?我可以更改某种 boolean 值
我在 iTerm2 中使用 tmux。 当我在 bash 中时,使用 Ctrl-L 清除屏幕有效,但在我拖尾服务器日志时不起作用。我该如何解决? 最佳答案 您可以使用 send-keys -R 清除当
如何以编程方式锁定和解锁 iPhone 的主屏幕(即设备本身)? 最佳答案 这是不可能的。但是,您可以在应用程序运行时“阻止”手机锁定。 [UIApplication sharedApplicatio
我的任务是创建社交网络 我有一个主页,显示用户通过 Canvas 创建的所有绘图。用户可以在自己的绘图上绘图,并且可以添加也有权在其绘图上绘图的贡献者。问题是他们可以以某种方式同时绘制。 我想做的是,
退出后,如何从我在应用程序中打开的最后一个屏幕继续。 比如说我有屏幕A,B和C,并且在关闭应用程序之前我在屏幕B上。我的问题是当我再次打开应用程序时如何进入屏幕B。 最佳答案 当SharedPrefe
我试图停止一个进程,然后休眠10秒钟,杀死下一个进程再休眠10秒钟,然后启动另一个进程。问题是一切都立即运行。所以我想开始的过程没有运行,因为其他人都没有停止。 Start-Process Power
我正在尝试以 HW 身份进行测验。我输入的回复应该会出现在屏幕上,但事实并非如此。我使用函数response()多次检查了“15”行和“17”行中出了什么问题。我没有发现任何错误,需要调试和编写正确语
我是一名优秀的程序员,十分优秀!