@Override public void create() { batch = new SpriteBatch(); // Load the UI skin skin = new Skin(Gdx.files.internal("skin/uiskin.json")); clickSound = Gdx.audio.newSound(Gdx.files.internal("sound/buttonClick.mp3")); menuMusic = Gdx.audio.newMusic(Gdx.files.internal("sound/menuMusic.mp3")); menuMusic.setLooping(true); // Load the current account if cached account = AccountManager.getLocalAccount(); // The first screen that shows up when the game starts Screen mainScreen = account == null ? new LoginScreen(this) : new MenuScreen(this); setScreen(mainScreen); }
ShareScoreScreen(final Klooni game, final Screen lastScreen, final int score, final boolean timeMode) { this.game = game; this.lastScreen = lastScreen; this.score = score; this.timeMode = timeMode; final Label.LabelStyle labelStyle = new Label.LabelStyle(); labelStyle.font = game.skin.getFont("font_small"); infoLabel = new Label("Generating image...", labelStyle); infoLabel.setColor(Klooni.theme.textColor); infoLabel.setAlignment(Align.center); infoLabel.layout(); infoLabel.setPosition( (Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f, (Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f); spriteBatch = new SpriteBatch(); }
/** * Replaces the top of the "deck" of screens with this screen.<br/> * Current screen (if any) {@link Screen#hide()} is called.<br/> * New screen {@link Screen#show()} is called.<br/> * Previous screen (if any) {@link Screen#dispose()} is called. */ @Override public void setScreen(Screen screen) { int activeScreen = screens.size() - 1; screens.add(screen); super.setScreen(screen); if (activeScreen > -1) { final Screen forDisposal = screens.remove(activeScreen); Gdx.app.postRunnable(new Runnable() { @Override public void run() { forDisposal.dispose(); } }); } }
/** * Discards current screen and displays previous screen.<br/> * Has no effect if there is no previous screen to go back to. */ public void previousScreen() { if (screens.size() < 2) { return; } // remove current screen from "deck" final Screen forRemoval = screens.remove(screens.size() - 1); // hide it forRemoval.hide(); // show new "top" screen super.setScreen(screens.get(screens.size() - 1)); // schedule for dispose the no longer shown screen Gdx.app.postRunnable(new Runnable() { @Override public void run() { forRemoval.dispose(); } }); }
public Screen setPreviousScreen(){ Screen currentScreen = getScreen(); if(currentScreen instanceof CampainMap){//only in back button GDefence.getInstance().user.save(); GDefence.getInstance().user.flush();//empty user info in main menu setScreen(campainChoose); }else if(currentScreen instanceof OptionScreen){ setScreen(mainMenu); }else if(currentScreen instanceof CampainChoose){ setScreen(mainMenu); }else if(currentScreen instanceof Arsenal){ setScreen(campainMap); }else if(currentScreen instanceof Store){ setScreen(campainMap); }else if(currentScreen instanceof Smith){ setScreen(campainMap); }else if(currentScreen instanceof LevelPreparationScreen){ setScreen(campainMap); } return null; }
private void leaveAnimation(final Screen setScreen){ //setup a parallel event Timeline.createParallel().beginParallel() .push(Tween.to(heading, ActorAccessor.Y, 2f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level1, ActorAccessor.Y, 1.5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level2, ActorAccessor.Y, 1.5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level3, ActorAccessor.Y, 1.5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level4, ActorAccessor.Y, 1f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level5, ActorAccessor.Y, 1f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level6, ActorAccessor.Y, 1f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l1, ActorAccessor.Y, 1.25f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l2, ActorAccessor.Y, 1.25f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l3, ActorAccessor.Y, 1.25f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l4, ActorAccessor.Y, .75f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l5, ActorAccessor.Y, .75f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l6, ActorAccessor.Y, .75f).target(-Gdx.graphics.getHeight())) .push(Tween.to(more, ActorAccessor.Y, .5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l7, ActorAccessor.Y, .5f).target(-Gdx.graphics.getHeight())).end().setCallback(new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { ((Game)Gdx.app.getApplicationListener()).setScreen(setScreen); } }).start(tweenManager); }
private void leaveAnimation(final Screen setScreen){ //setup a parallel event Timeline.createParallel().beginParallel() .push(Tween.to(heading, ActorAccessor.Y, 2f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level1, ActorAccessor.Y, 1.5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l1, ActorAccessor.Y, 1.25f).target(-Gdx.graphics.getHeight())) .push(Tween.to(level2, ActorAccessor.Y, 1.5f).target(-Gdx.graphics.getHeight())) .push(Tween.to(l2, ActorAccessor.Y, 1.25f).target(-Gdx.graphics.getHeight())) .end().setCallback(new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { ((Game)Gdx.app.getApplicationListener()).setScreen(setScreen); } }).start(tweenManager); }
@Override public void onReceiveUnreliableTournamentCustomMessage(NextpeerTournamentCustomMessage message) { try { Screen screen = SkiFun.this.getScreen(); if (screen==null) return; // Act only if the current scene is the game screen if (screen instanceof GameScreen) { GameScreen gameScreen = (GameScreen)screen; // Pass the received data to the world instance which responsible on the game updates if (message==null) return; if (gameScreen.world==null) return; gameScreen.world.onReceiveTournamentCustomMessage(message); } } catch(Exception e) { e.printStackTrace(); } }
/** Sets the current screen. {@link Screen#hide()} is called on any old screen, and {@link Screen#show()} is called on the new * screen, if any. * @param screen may be {@code null} */ @Override public void setScreen(Screen screen) { screen.show(); if (transitionRunning) Gdx.app.log(FadingGame.class.getSimpleName(), "Changed Screen while transition in progress"); if (this.screen == null) { this.screen = screen; } else { if (screenTransition == null) { this.screen.hide(); this.screen = screen; } else { this.nextScreen = screen; this.screen.pause(); this.nextScreen.pause(); currentTransitionTime = 0; transitionRunning = true; notifyStarted(); } } this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
/** * Build a new TextButton with factory default button style * * @param context * a Game context where * @param label * string button's label * @param nextScreenAfterClick * the next screen that will be showed after button click * @return a new TextButton ready to be added to a stage */ public TextButton makeMenuButton(final Game game, final String label, final Screen nextScreenAfterClick) { button = new TextButton(label, textButtonStyle); button.setHeight(menuItemHeight); button.setWidth(menuItemWidth); button.setPosition(initPosXMenu, initPosYMenu - menuItemHeight * menuItemNumber); menuItemNumber++; button.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Assets.playSound(Assets.clickSound); game.getScreen().dispose(); game.setScreen(nextScreenAfterClick); } }); return button; }
public void processTouch(float x, float y) { if (balls.isTouched(x, y)){ incrementChainLength(); Ball ball = balls.getTouchedBall(x, y); ball.playSound(Constants.VOLUME); updateScore(ball); lines.addCurrentLine(ball); ball.touch(); if (ball.getType() == BallType.GRAY){ Gdx.input.vibrate(Constants.VIBRATION_DURATION); Screen gameOver = new GameOver(balls, lines, offset, score, longestChain, stopwatch.getElapsedTimeSecs()); Chainball.setScreen(gameOver); } else if (ball.getType() == BallType.RED){ Gdx.input.vibrate(Constants.VIBRATION_DURATION); } } lines.updateCurrentLine(x, y); }
@Override public final void navigateToLevel(final String levelID) { Gdx.app.log("NavigationManager", "NavigateToLevel"); try { if (game.getScreen() != null) { InputManager.clear(); game.getScreen().dispose(); game.setScreen(null); } if (levelIDHistory.isEmpty() || !levelIDHistory.peek().equals(levelID)) { levelIDHistory.push(levelID); } Screen screen = levelManager.getScreenByLevelID(levelID); game.setScreen(screen); } catch (LevelLoadException e) { e.printStackTrace(); navigateToLevel("worldmap"); } }
@Override public void create () { Env.init(this); camera = new OrthographicCamera(); viewport = new ExtendViewport(960, 720, 1280, 720, camera); assets = new Assets(); tweenManager = new TweenManager(); Tween.setCombinedAttributesLimit(4); Tween.registerAccessor(Actor.class, new ActorTweener()); screens = new ObjectMap<Class<? extends Screen>, Screen>(); screens.put(GameScreen.class, new GameScreen()); setScreen(GameScreen.class); }
@Override public void create() { screenlist = new Screen[SCREEN_NUMBER]; screenlist[SCREEN_SPLASH] = new SplashScreen(SCREEN_SPLASH); screenlist[SCREEN_BATTLE] = new BattleScreen(); // Creating global resource managers queueAssets(); animman = new AnimationManager(); setScreen(screenlist[SCREEN_SPLASH]); nextscreen = SCREEN_SPLASH; changescreen = false; debugtext = new BitmapFont(); batch = new SpriteBatch(); Gdx.app.setLogLevel(Application.LOG_DEBUG); }
public void setScreen(AbstractScreen screen) { if (screen.isCached()) { screensCache.put(screen.getCacheName(), screen); } if (!screen.isStarted()) { screen.start(); } Gdx.input.setInputProcessor(screen); Screen current = getScreen(); super.setScreen(screen); if (current != null) { AbstractScreen currentScreen = (AbstractScreen) current; if (!currentScreen.isCached()) { currentScreen.stop(); } } }
@Override public void setScreen(final Screen screen) { System.out.println("SET SCREEN"); if (currentScreen != null) { ((BaseScreen)screen).initialize(); currentScreen.fadeOut(); TimerTask task = new TimerTask() { @Override public void run() { FourInALine.super.setScreen(screen); } }; transitionTimer.schedule(task, (long)(currentScreen.animationTime * 1000)); } else super.setScreen(screen); currentScreen = (BaseScreen)screen; }
@Override public final void dispose() { this.screen = null; for (Screen s : screens.values()) { s.pause(); s.dispose(); } this.batch.dispose(); }
public CreateScreen(CatanGame pGame, Screen parentScreen) { this.parentScreen = parentScreen; game = pGame; boardHexes = new ArrayList<>(); boardOrigin = new MutablePair<>(); setupBoardOrigin(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
@Override public void create () { VisUI.load(); screens = new Stack<Screen>(); pushScreen(new HostOrJoinScreen(this)); }
/** * Transition to screen after delay in seconds. */ public void transition(Class<? extends Screen> screen, float delay) { E() .script( sequence( delay(seconds(delay)), add(new Transition(screen)) ) ); }
public ScorePresenter(final Asteroids game, final Screen parent, List<PlayerData> playerData) { this.parent = parent; this.game = game; this.playerData = playerData; this.view = new ScoreView(game.getBatch(), new ViewHandler()); Collections.sort(playerData, new Comparator<PlayerData>() { @Override public int compare(PlayerData s, PlayerData t1) { return t1.totalScore - s.totalScore; } }); }
SettingsPresenter(final Asteroids game, final Screen parent) { this.parent = parent; this.game = game; this.view = new SettingsView(game.getBatch(), new ViewHandler()); this.audioService = ServiceLocator.getAppComponent().getAudioService(); this.settingsService = ServiceLocator.appComponent.getSettingsService(); musicVolume = settingsService.getInt(ISettingsService.MUSIC_VOLUME, 100); }
BaseGamePresenter(Asteroids game, Screen parent) { this.parent = parent; this.game = game; engine = new PooledEngine(); initializeEntityComponent(engine); controllerInputHandler = new ControllerInputHandler(engine); setupView(); setupWorld(); setupEngine(engine, game.getBatch()); world.run(); }
public TransitionScreen(Klooni game, Screen from, Screen to, boolean disposeAfter) { this.disposeAfter = disposeAfter; this.game = game; fromScreen = from; toScreen = to; spriteBatch = new SpriteBatch(); }
public void exitCurrentExample (){ Screen exitedScreen = getScreen(); setScreen(menuScreen); if (exitedScreen != null) exitedScreen.dispose(); selectBox.setSelected(((Example)exitedScreen).getClass()); }
@Override public void dispose (){ Screen exitedScreen = getScreen(); if (exitedScreen != null) exitedScreen.dispose(); setScreen(null); spriteBatch.dispose(); skin.dispose(); }
/** * Registers the given screen into the {@link ScreenManager}. * Initializes the given {@link Screen} with a default constructor, if init is true. * * @param type type of the {@link Screen} * @return the old registered instance */ public synchronized <T extends Screen> T register(Class<T> type) { if (screenMap.containsKey(type)) throw new IllegalArgumentException("Screen already registerd: " + ClassReflection.getSimpleName(type)); T screen = null; try { screen = ClassReflection.newInstance(type); } catch (ReflectionException e) { throw new IllegalArgumentException(e); } return (T) screenMap.put(type, screen); }
public synchronized <T extends Screen> T get(Class<T> type, boolean init) { if (init && !isRegistered(type)) register(type); if (!isRegistered(type)) throw new IllegalArgumentException("Screen not registered: " + ClassReflection.getSimpleName(type)); return (T) screenMap.get(type); }
@Override public synchronized void dispose() { for (Iterator<Map.Entry<Class<? extends Screen>, Screen>> iter = screenMap.entrySet().iterator(); iter.hasNext(); ) { Map.Entry<Class<? extends Screen>, Screen> entry = iter.next(); entry.getValue().dispose(); iter.remove(); } }
public void draw() { game.batch.draw(gameOver, 231, 450, GAME_OVER_TEXT_WIDTH, GAME_OVER_TEXT_HEIGHT ); if (Gdx.input.getX() < buttonX && Gdx.input.getX() > CENTER_X && Gdx.input.getY() > topY && Gdx.input.getY() < TOP_Y) { game.batch.draw(exitButtonActive, CENTER_X, 300, BUTTON_WIDTH, BUTTON_HEIGHT ); if (Gdx.input.isTouched()) { game.gameScreen.setState(GameScreen.STATE.EXIT_YES); game.setScreen((Screen)game.getGameScreen()); } } else { game.batch.draw(exitButtonInactive, CENTER_X, 300, BUTTON_WIDTH, BUTTON_HEIGHT); } }
/** * Set a screen and then dispose of the old screen * * This can be called from any thread * * @param screen - the new screen to switch to */ public void setScreenAndDisposeOld(Screen screen) { Gdx.app.postRunnable(() -> { Screen old = getScreen(); setScreen(screen); old.dispose(); }); }
public static void setCurrentScreen(Screen currentScreen) { // Because GameScreen requires special disposing, we don't dispose it here. if (ScreenManager.currentScreen != null && ! (ScreenManager.currentScreen instanceof GameScreen)) ScreenManager.currentScreen.dispose(); String name = currentScreen.getClass().getSimpleName(); log.print("Changed screen to '%s'", name); ScreenManager.currentScreen = currentScreen; }
/** * Transition to screen after delay in seconds. */ public void transition(Class<? extends Screen> screen, float delay) { E.create(world) .schedule( sequence( delay(seconds(delay)), add(new Transition(screen)) ) ); }
@Override public Screen initState(Object ... vars) { int[] dim = new int[]{0, 0, super.SCREEN_DEFAULT_WIDTH, super.SCREEN_DEFAULT_HEIGHT}; this.init_base(dim); System.out.println(super.SCREEN_WIDTH+"::"+super.SCREEN_HEIGHT); super.initializationEnded = true; this.resize(super.SCREEN_WIDTH, super.SCREEN_HEIGHT); System.gc(); return this; }
public void setScreen(final Screen screen) { Gdx.input.setInputProcessor(null); fx.fadeOut(1f, TweenEquations.easeInQuad, new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { dispose(); game.setScreen(screen); } }); }
@Override public void dispose() { log("Dispose"); super.dispose(); for (Screen screen : screens) { screen.dispose(); } }
public Screen getScreen(ScreenType type) { switch (type) { case MAIN_MENU: return mainMenuScreen; case NEW_GAME: return newGameScreen; case GAME: return mainGameScreen; case LOAD_GAME: return loadGameScreen; } return null; }
public void showScreen(ScreenEnum screenEnum, Object... params) { // Get current screen to dispose it Screen currentScreen = game.getScreen(); // Show new screen AbstractScreen newScreen = screenEnum.getScreen(params); newScreen.buildStage(); game.setScreen(newScreen); // Dispose previous screen if (currentScreen != null) { currentScreen.dispose(); } }
public static void changeScreen(Screen screen) { if (INSTANCE.getScreen() != null) { INSTANCE.getScreen().dispose(); } INSTANCE.setScreen(screen); screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); if (screen instanceof InputAdapter) { Gdx.input.setInputProcessor((InputAdapter) screen); } }