com.badlogic.gdx.Application Java Examples

The following examples show how to use com.badlogic.gdx.Application. 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: CubesShaderProvider.java    From Cubes with MIT License 6 votes vote down vote up
public static Setting getSetting() {
  return new BooleanSetting(false) {
    @Override
    public boolean shouldDisplay() {
      return Compatibility.get().getApplicationType() == Application.ApplicationType.Desktop;
    }

    @Override
    public void onChange() {
      super.onChange();
      Log.debug("Emptying shader cache");
      for (int i = 0; i < shaders.length; i++) {
        if (shaders[i] != null) shaders[i].dispose();
        shaders[i] = null;
      }
    }
  };
}
 
Example #2
Source File: PlatformDistributor.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
/**
 * Creates platform specific object by reflection.
 * <p>
 * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()}
 * <p>
 * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object.
 *
 * @throws PlatformDistributorException Throws when something is wrong with environment
 */
@SuppressWarnings("unchecked")
protected PlatformDistributor() {
    String className = null;
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        className = getAndroidClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
        className = getIOSClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        className = getWebGLClassName();
    } else {
        return;
    }
    try {
        Class objClass = ClassReflection.forName(className);
        platformObject = (T) ClassReflection.getConstructor(objClass).newInstance();
    } catch (ReflectionException e) {
        throw new PlatformDistributorException("Something wrong with environment", e);
    }
}
 
Example #3
Source File: GdxAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void playSourceInstance(AudioNode audioNode) {
    Gdx.app.log("GdxAudioRenderer", "playSourceInstance");
    GdxAudioData audioData;
    audioData = (GdxAudioData) audioNode.getAudioData();
    Music music = musicMap.get(audioNode);
    if (Gdx.app.getType() == Application.ApplicationType.iOS && audioData.getAssetKey().getName().endsWith(".ogg")) {
        return;
    }
    if (music == null) {
        music = Gdx.audio.newMusic(GdxAssetCache.getFileHandle(audioData.getAssetKey().getName()));
        musicMap.put(audioNode, music);
    }
    music.stop();
    music.play();
    audioNode.setStatus(AudioNode.Status.Playing);
}
 
Example #4
Source File: MusicController.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public void next() {
  stop();
  if (PLAYLIST.isEmpty()) {
    return;
  }

  this.asset = PLAYLIST.removeFirst();
  ASSETS.load(asset, Music.class);
  ASSETS.finishLoadingAsset(asset);
  this.track = ASSETS.get(asset, Music.class);
  track.setOnCompletionListener(this);
  track.play();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, "Now playing \"" + asset + "\"");
  }
}
 
Example #5
Source File: ShaderUtils.java    From Mundus with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and links shader.
 *
 * @param vertexShader
 *            path to vertex shader
 * @param fragmentShader
 *            path to fragment shader
 *
 * @return compiled shader program
 */
public static ShaderProgram compile(String vertexShader, String fragmentShader) {
    String vert;
    String frag;

    if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        vert = Gdx.files.internal(vertexShader).readString();
        frag = Gdx.files.internal(fragmentShader).readString();
    } else {
        vert = Gdx.files.classpath(vertexShader).readString();
        frag = Gdx.files.classpath(fragmentShader).readString();
    }

    ShaderProgram program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }

    return program;
}
 
Example #6
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange_detach() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        GwtDataPromisesManager.removeDataPromise(testReference);
        Gdx.app = Mockito.mock(Application.class);

        // When
        FutureListenerPromise promise = ((FutureListenerPromise) database.inReference(testReference).onDataChange(String.class).subscribe());
        promise.doComplete(testReference);
        PowerMockito.doReturn(true).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        promise.cancel();

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.offValue(eq(testReference));
    }
 
Example #7
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void onChildChange() throws Exception {
    // Given
    String testReference = "test_reference";
    Database database = new Database();
    mockStatic(QueryOnChildChange.class);
    QueryOnChildChange query = spy(new QueryOnChildChange(database, testReference));
    PowerMockito.whenNew(QueryOnChildChange.class).withAnyArguments().thenReturn(query);
    Gdx.app = Mockito.mock(Application.class);
    PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference + "child_added");
    Class dataType = String.class;

    // When
    ((FuturePromise) database.inReference(testReference)
            .onChildChange(dataType, ChildEventType.ADDED).subscribe()).doComplete(testReference);

    // Then
    PowerMockito.verifyStatic(QueryOnChildChange.class);
    QueryOnChildChange.onEvent(eq(testReference), eq("child_added"), Mockito.any(DatabaseReference.class));
}
 
Example #8
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void readValue() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryReadValue.class);
        QueryReadValue query = spy(new QueryReadValue(database, testReference));
        PowerMockito.whenNew(QueryReadValue.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        Class dataType = String.class;


        // When
        ((FuturePromise) database.inReference(testReference).readValue(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(ReadValueQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryReadValue.class);
        QueryReadValue.once(Mockito.any(DatabaseReference.class), Mockito.any(ConverterPromise.class));
    }
 
Example #9
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        Class dataType = String.class;

        // When
        ((FuturePromise) database.inReference(testReference).onDataChange(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.onValue(eq(testReference), Mockito.any(DatabaseReference.class));
    }
 
Example #10
Source File: AndroidContextTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    PowerMockito.mockStatic(GdxNativesLoader.class);
    AndroidApplication application = PowerMockito.mock(AndroidApplication.class);
    Mockito.when(application.getType()).thenReturn(Application.ApplicationType.Android);
    Gdx.app = application;
    PowerMockito.mockStatic(Timer.class);
    PowerMockito.when(Timer.post(any(Timer.Task.class))).then(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((Timer.Task) invocation.getArgument(0)).run();
            return null;
        }
    });
    GdxFIRApp.setThrowFailureByDefault(false);
}
 
Example #11
Source File: DesktopCompatibility.java    From Cubes with MIT License 6 votes vote down vote up
protected DesktopCompatibility(DesktopLauncher desktopLauncher, Application.ApplicationType applicationType, String[] arg) {
  super(desktopLauncher, applicationType);
  this.arg = arg;

  String str = (System.getProperty("os.name")).toUpperCase();
  if (str.contains("WIN")) {
    os = OS.Windows;
  } else if (str.contains("MAC")) {
    os = OS.Mac;
  } else if (str.contains("LINUX")) {
    os = OS.Linux;
  } else {
    os = OS.Unknown;
  }

  modLoader = new DesktopModLoader();
}
 
Example #12
Source File: DiceHeroes.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.input.setCatchBackKey(true);
    Gdx.input.setCatchMenuKey(true);
    Config.clearRegions();
    Config.shapeRenderer = new ShapeRenderer();
    Config.assetManager = new AssetManager();
    Config.preferences = new DicePreferences(Gdx.app.getPreferences("com.vlaaad.dice.preferences"), this);
    Tutorial.killAll();

    setState(new IntroState(new IntroState.Callback() {
        @Override public void onEnded() {
            setScale(Config.preferences.getScale());
            setState(new LoadGameResourcesState(new LoadGameResourcesState.Callback() {
                @Override
                public void onResourcesLoaded() {
                    start();
                }
            }));
        }
    }));
}
 
Example #13
Source File: GdxCvarManager.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void save(Cvar<T> cvar) {
  String alias = cvar.getAlias();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG && !isManaging(cvar)) {
    throw new CvarManagerException("%s must be managed by this CvarManager", alias);
  }

  StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
  if (serializer == null) {
    throw new CvarManagerException("%s cannot be saved (no serializer found for %s)", alias, cvar.getType().getName());
  }

  T value = cvar.get();
  String serialization = serializer.serialize(value);
  PREFERENCES.putString(alias, serialization);
  PREFERENCES.flush();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, String.format("%s saved as \"%s\" (raw: \"%s\")", alias, value, serialization));
  }
}
 
Example #14
Source File: UserDataHelper.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
void saveUserData(UserData userData) {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    String toSave = new Yaml(options).dump(UserData.serialize(userData));
    if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
        Gdx.files.local("game.save").writeString(toSave, false);
        return;
    }
    try {
        loadKey();
        byte[] bytes = encrypt(key, toSave.getBytes("UTF-8"));
        Gdx.files.local("game.save").writeBytes(bytes, false);
    } catch (Exception e) {
        Gdx.files.local("game.save").writeString(toSave, false);
    }
}
 
Example #15
Source File: Screenshot.java    From Cubes with MIT License 6 votes vote down vote up
public static Setting screenshotResolutionSetting() {
  return new DropDownSetting(resolutions) {
    @Override
    public void onChange() {
      if ("normal".equals(selected) || "max".equals(selected)) return;

      IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
      Gdx.gl20.glGetIntegerv(GL20.GL_MAX_VIEWPORT_DIMS, intBuffer);
      int maxWidth = intBuffer.get(0);
      int maxHeight = intBuffer.get(1);

      int[] resolution = resolutionMap.get(selected);
      if (resolution[0] > maxWidth || resolution[1] > maxHeight) selected = "normal";
    }

    @Override
    public boolean shouldDisplay() {
      return Compatibility.get().getApplicationType() == Application.ApplicationType.Desktop;
    }
  };
}
 
Example #16
Source File: GdxKeyMapper.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public int[] load(MappedKey key) {
  String alias = key.getAlias();
  String serializedValue = PREFERENCES.getString(alias);
  if (serializedValue == null || serializedValue.isEmpty()) return null;

  int[] assignments;
  try {
    assignments = IntArrayStringSerializer.INSTANCE.deserialize(serializedValue);
  } catch (SerializeException t) {
    Gdx.app.error(TAG, String.format("removing %s from preferences (invalid save format): %s", alias, t.getMessage()), t);
    PREFERENCES.remove(alias);
    PREFERENCES.flush();
    throw t;
  }

  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    String[] keycodeNames = getKeycodeNames(assignments);
    Gdx.app.debug(TAG, String.format("%s [%s] loaded as %s (raw: \"%s\")",
        key.getName(), key.getAlias(), Arrays.toString(keycodeNames), serializedValue));
  }

  KEYS.put(alias.toLowerCase(), key);
  return assignments;
}
 
Example #17
Source File: MSI.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
}
 
Example #18
Source File: GdxKeyMapper.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void save(MappedKey key) {
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG && !isManaging(key)) {
    Gdx.app.debug(TAG, String.format("key %s is being saved by a key mapper not managing it", key));
  }

  int[] assignments = key.getAssignments();
  String serializedValue = IntArrayStringSerializer.INSTANCE.serialize(assignments);
  PREFERENCES.putString(key.getAlias(), serializedValue);
  PREFERENCES.flush();
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    String[] keycodeNames = getKeycodeNames(assignments);
    Gdx.app.debug(TAG, String.format("%s [%s] saved as %s (raw: \"%s\")",
        key.getName(), key.getAlias(), Arrays.toString(keycodeNames), serializedValue));
  }
}
 
Example #19
Source File: DesktopLauncher.java    From Radix with MIT License 6 votes vote down vote up
public static void main (String[] arg) {
LwjglApplicationConfiguration config;
      FileHandle glConfigFile = new FileHandle("conf/lwjgl.json");
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      if(!glConfigFile.exists()) {
          config = createDefaultConfig();
          glConfigFile.writeString(gson.toJson(config), false);
      } else {
          try {
              config = gson.fromJson(glConfigFile.readString(), LwjglApplicationConfiguration.class);
          } catch (Exception e) {
              e.printStackTrace();
              System.err.println("Error reading lwjgl config! Using defaults.");
              config = createDefaultConfig();
          }
      }
new LwjglApplication(new RadixClient(), config);
      Gdx.app.setLogLevel(Application.LOG_DEBUG);
  }
 
Example #20
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnHTMLGDXFacebookWhenOnWebGL() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.WebGL);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(HTMLGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML)).thenReturn(HTMLGDXFacebook.class);
        when(ClassReflection.getConstructor(HTMLGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof HTMLGDXFacebook);
}
 
Example #21
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnDesktopGDXFacebookWhenOnDesktop() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.Desktop);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(DesktopGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP)).thenReturn(DesktopGDXFacebook.class);
        when(ClassReflection.getConstructor(DesktopGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof DesktopGDXFacebook);
}
 
Example #22
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnIOSGDXFacebookWhenOnIOS() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(IOSGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS)).thenReturn(IOSGDXFacebook.class);
        when(ClassReflection.getConstructor(IOSGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof IOSGDXFacebook);
}
 
Example #23
Source File: GdxCvarManager.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T load(Cvar<T> cvar) {
  String alias = cvar.getAlias();
  StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
  if (serializer == null) {
    try {
      throw new CvarManagerException("%s cannot be loaded (no deserializer found for %s)", alias, cvar.getType().getName());
    } finally {
      return cvar.getDefault();
    }
  }

  String serialization = PREFERENCES.getString(alias, null);
  if (serialization == null) return cvar.getDefault();

  T deserialization = serializer.deserialize(serialization);
  if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) {
    Gdx.app.debug(TAG, String.format("%s loaded as \"%s\" [%s] (raw: \"%s\")",
        alias, deserialization, deserialization.getClass().getName(), serialization));
  }

  return deserialization;
}
 
Example #24
Source File: GameScreen.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void create() {
    if (created) return;
    created = true;

    isDebug = DEBUG && Gdx.app.getType() == Application.ApplicationType.Desktop;

    if (DEBUG_TOUCHPAD || Gdx.app.getType() == Application.ApplicationType.Android) {
      touchpad = new Touchpad(10, new Touchpad.TouchpadStyle() {{
        //background = new TextureRegionDrawable(Riiablo.assets.get(touchpadBackgroundDescriptor));
        background = null;
        knob = new TextureRegionDrawable(Riiablo.assets.get(touchpadKnobDescriptor));
      }});
      touchpad.setSize(164, 164);
      touchpad.setPosition(0, mobilePanel != null ? mobilePanel.getHeight() : 0);
      stage.addActor(touchpad);
      if (!DEBUG_TOUCHPAD) touchpad.toBack();
    }

    // TODO: sort children based on custom indexes
    controlPanel.toFront();
    output.toFront();
    if (mobilePanel != null) mobilePanel.toFront();
//  if (mobileControls != null) mobileControls.toFront();
    if (touchpad != null) touchpad.toBack();
    input.toFront();
    escapePanel.toFront();

    if (Gdx.app.getType() == Application.ApplicationType.Android
     || Riiablo.defaultViewport.getWorldHeight() == Riiablo.MOBILE_VIEWPORT_HEIGHT) {
      renderer.zoom(Riiablo.MOBILE_VIEWPORT_HEIGHT / (float) Gdx.graphics.getHeight());
    } else {
      renderer.zoom(Riiablo.DESKTOP_VIEWPORT_HEIGHT / (float) Gdx.graphics.getHeight());
    }
    renderer.resize();
  }
 
Example #25
Source File: TestClient.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
  public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);

    group = new NioEventLoopGroup();
    try {
      Bootstrap b = new Bootstrap()
          .group(group)
          .channel(NioSocketChannel.class)
          .option(ChannelOption.SO_KEEPALIVE, true)
          .option(ChannelOption.TCP_NODELAY, true)
          .handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) {
              UnicastEndpoint<ByteBuf> endpoint = new TcpEndpoint(ch, TestClient.this);
              TestClient.this.endpoint = endpoint;
              ch.pipeline()
                  .addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
              ;
            }
          });

      ChannelFuture f = b.connect("localhost", Main.PORT).sync();
      sendConnectionPacket();
//      sendConnectionPacket();
//      sendDisconnectPacket();
    } catch (Throwable t) {
      Gdx.app.error(TAG, t.getMessage(), t);
      Gdx.app.exit();
    }
  }
 
Example #26
Source File: ExampleMain.java    From gdx-smart-font with MIT License 5 votes vote down vote up
@Override
public void create() {
	Gdx.app.setLogLevel(Application.LOG_DEBUG);
	SmartFontGenerator fontGen = new SmartFontGenerator();
	FileHandle exoFile = Gdx.files.local("LiberationMono-Regular.ttf");
	BitmapFont fontSmall = fontGen.createFont(exoFile, "exo-small", 24);
	BitmapFont fontMedium = fontGen.createFont(exoFile, "exo-medium", 48);
	BitmapFont fontLarge = fontGen.createFont(exoFile, "exo-large", 64);

	stage = new Stage();

	Label.LabelStyle smallStyle = new Label.LabelStyle();
	smallStyle.font = fontSmall;
	Label.LabelStyle mediumStyle = new Label.LabelStyle();
	mediumStyle.font = fontMedium;
	Label.LabelStyle largeStyle = new Label.LabelStyle();
	largeStyle.font = fontLarge;

	Label small = new Label("Small Font", smallStyle);
	Label medium = new Label("Medium Font", mediumStyle);
	Label large = new Label("Large Font", largeStyle);

	Table table = new Table();
	table.setFillParent(true);
	table.align(Align.center);
	stage.addActor(table);

	table.defaults().size(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 6);

	table.add(small).row();
	table.add(medium).row();
	table.add(large).row();
}
 
Example #27
Source File: Game.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void resize(int width, int height) {
	if (width == 0 || height == 0){
		return;
	}

	//If the EGL context was destroyed, we need to refresh some data stored on the GPU.
	// This checks that by seeing if GLVersion has a new object reference
	if (versionContextRef != Gdx.graphics.getGLVersion()) {
		versionContextRef = Gdx.graphics.getGLVersion();
		Blending.useDefault();
		TextureCache.reload();
		Vertexbuffer.refreshAllBuffers();
	}
	
	if (height != Game.height || width != Game.width) {
		
		Game.width = width;
		Game.height = height;
		
		//TODO might be better to put this in platform support
		if (Gdx.app.getType() != Application.ApplicationType.Android){
			Game.dispWidth = Game.width;
			Game.dispHeight = Game.height;
		}
		
		resetScene();
	}
}
 
Example #28
Source File: BreakpointsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  int[] efcrs = new int[25];
  Arrays.fill(efcrs, Integer.MIN_VALUE);

  int[] breakpoints = new int[25];
  Arrays.fill(breakpoints, Integer.MIN_VALUE);

  int numFrames = 14;
  int speed = 256;
  for (int fcr = 0; fcr <= 200; fcr++) {
    int efcr = efcr(fcr);
    int i = frames(numFrames, speed, efcr);
    if (breakpoints[i] == Integer.MIN_VALUE) {
      breakpoints[i] = fcr;
      efcrs[i] = efcr;
    }
  }

  for (int i = breakpoints.length - 1; i >= 0; i--) {
    if (breakpoints[i] == Integer.MIN_VALUE) continue;
    Gdx.app.log(TAG, String.format("%2d=%-3d (%d)", i, breakpoints[i], efcrs[i]));
  }

  Gdx.app.exit();
}
 
Example #29
Source File: Main.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  bossGroup = new NioEventLoopGroup();
  workerGroup = new NioEventLoopGroup();
  try {
    ServerBootstrap b = new ServerBootstrap()
        .group(bossGroup, workerGroup)
        .channel(NioServerSocketChannel.class)
        .childHandler(new ChannelInitializer<SocketChannel>() {
          @Override
          protected void initChannel(SocketChannel ch) {
            TcpEndpoint endpoint = new TcpEndpoint(ch, Main.this);
            Main.this.endpoint = endpoint;
            ch.pipeline()
                .addFirst(connectionLimiter)
                .addLast(new ChannelInboundHandlerAdapter() {
                  @Override
                  public void channelInactive(ChannelHandlerContext ctx) throws Exception {
                    super.channelInactive(ctx);
                    notifyChannelInactive(ctx);
                  }
                })
                .addLast(new SizePrefixedDecoder())
                .addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
                ;
          }
        })
        .option(ChannelOption.SO_BACKLOG, 128)
        .childOption(ChannelOption.TCP_NODELAY, true)
        .childOption(ChannelOption.SO_KEEPALIVE, true);

    ChannelFuture f = b.bind(PORT).sync();
  } catch (Throwable t) {
    Gdx.app.error(TAG, t.getMessage(), t);
    Gdx.app.exit();
  }
}
 
Example #30
Source File: MyGdxGame.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void create () {
		Gdx.app.setLogLevel(Application.LOG_DEBUG);

		setScreen(new MainMenuScreen(this));
//		setScreen(new SettingsScreen(this, StandardizedInterface.getInstance()));

	}