Archive for 2019

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.utils.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.viewport.*;
import com.badlogic.gdx.audio.*;

public class MyGdxGame implements ApplicationListener{
Music m;
private Stage stage,stage2;
    private Texture myTexture,tex2;
    private TextureRegion myTextureRegion,reg2;
    private TextureRegionDrawable myTexRegionDrawable,draw2;
    private ImageButton button,button2;

    @Override
    public void create(){  
m =Gdx.audio.newMusic(Gdx.files.internal("ms.mp3"));
tombol1();
tombol2();
    Gdx.input.setInputProcessor(new InputMultiplexer(stage,stage2));}
   
@Override
    public void render(){
renderTombol1();
renderTombol2();}

///////////////////TOMBOL SATU////////////////////////////////
public void tombol1(){
myTexture = new Texture(Gdx.files.internal("android.jpg"));
        myTextureRegion = new TextureRegion(myTexture,0,0,100,100);
        myTexRegionDrawable = new TextureRegionDrawable(myTextureRegion);
        button = new ImageButton(myTexRegionDrawable); //Set the button up
        stage = new Stage(new ScreenViewport()); //Set up a stage for the ui
stage.addActor(button); }
public void renderTombol1(){
stage2.act(Gdx.graphics.getDeltaTime()); //Perform ui logic
        stage2.draw(); //Draw the ui
button2.addListener(new EventListener(){
@Override
public boolean handle(Event event){
m.stop();
return false;}});}
////////////////////TOMBOL DUA///////////////////////////////////////
public void tombol2(){
tex2 = new Texture(Gdx.files.internal("android.jpg"));
        reg2= new TextureRegion(tex2,50,0,100,100);
        draw2 = new TextureRegionDrawable(reg2);
        button2 = new ImageButton(draw2); //Set the button up
        button2.setPosition(300,0);
stage2 = new Stage(new ScreenViewport()); //Set up a stage for the ui
        stage2.addActor(button2); }
public void renderTombol2(){
stage.act(Gdx.graphics.getDeltaTime()); //Perform ui logic
stage.draw(); //Draw the ui
button.addListener(new EventListener(){
@Override
public boolean handle(Event even)
    {m.play(); return false;}});
}
//////////////////////////////////////////////////////////////////////
@Override
public void resize(int p1, int p2){}
@Override
public void pause(){}
@Override
public void resume(){}
@Override
public void dispose(){}
}

[LIBGDX] ImageButton Multi Stage

Posted by : Unknown 0 Comments

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.math.*;

public class MyGdxGame implements ApplicationListener{ TextureRegion objectA;
TextureRegion obj1;
TextureRegion obj2;
SpriteBatch batch;
BitmapFont font;
Vector2 velocityObj1;
Rectangle RegObj1;
Rectangle RegObj2;
Boolean hidup=true;
float time;

@Override
public void create(){
Texture object1=new Texture(Gdx.files.internal("obj1.png"));
Texture object2=new Texture(Gdx.files.internal("obj2.png"));
obj1=new TextureRegion(object1,0,0,100,100);
obj2=new TextureRegion(object2,0,0,100,100);
RegObj1 =new Rectangle();
RegObj1.width=object1.getWidth();
RegObj1.height=object1.getHeight();
RegObj1.x=0;
RegObj1.y=0;
RegObj2=new Rectangle();
RegObj2.width=object2.getWidth();
RegObj2.height=object2.getHeight();
RegObj2.x=300;
RegObj2.y=0;
velocityObj1=new Vector2(10,0);
batch=new SpriteBatch();
font=new BitmapFont();
font.setColor(Color.RED);
font.setScale(2);
hidup=false;
}

@Override
public void render(){
Gdx.gl.glClearColor(1,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT|GL20.GL_DEPTH_BUFFER_BIT);
batch.begin();
batch.draw(obj1,RegObj1.x,0,100,100);
batch.draw(obj2,RegObj2.x,0,100,100);
RegObj2.x=350;
if(hidup){
font.draw(batch,"Collision Detected",100,500);
}
batch.end();
time+=Gdx.graphics.getDeltaTime();
RegObj1.x=velocityObj1.x-=0*Gdx.graphics.getDeltaTime();
if(Gdx.input.isTouched()){
velocityObj1.x+=500*Gdx.graphics.getDeltaTime();
}
if(RegObj1.overlaps(RegObj2)){
hidup=true;
}
}

@Override
public void resize(int width, int height){
}

@Override
public void pause(){
}

@Override
public void resume(){
}

@Override
public void dispose()
{
batch.dispose();
font.dispose();
}

}

[LIBGDX] Collision Detection

Posted by : Unknown 0 Comments

Layar 1

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
public class MyGdxGame extends Game{
SpriteBatch batch;
BitmapFont font;

@Override
public void create(){
batch = new SpriteBatch();   
font = new BitmapFont();
font.setColor(Color.RED);
font.setScale(2);}

@Override
public void render(){       
//warna background
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
//tata letak text ganti X dan Y dengan angka
font.draw(batch, "tap dimana saja untuk pindah layar", 0, 400);
batch.end();
if(Gdx.input.isTouched()){
this.setScreen(new MainMenuScreen(this));}
super.render();}

@Override
public void dispose(){
batch.dispose();
font.dispose();}
   
@Override
public void resize(int width, int height){}
@Override
public void pause(){}
@Override
public void resume(){}
}

Layar 2

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import javax.microedition.khronos.opengles.*;
public class MainMenuScreen implements Screen{
final MyGdxGame game;
SpriteBatch batch;
Texture image;
TextureRegion imageRegion;
OrthographicCamera camera;
public MainMenuScreen(final MyGdxGame game){
this.game = game;}

@Override
public void show(){
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
image=new Texture(Gdx.files.internal("android.jpg"));
imageRegion=new TextureRegion(image,0,0,1000,1000);
batch=new SpriteBatch();}

@Override
public void render(float p1){
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(imageRegion,0,0,200, 200);
batch.end();}

@Override
public void resize(int p1, int p2){}
@Override
public void hide(){}
@Override
public void pause(){}
@Override
public void resume(){}
@Override
public void dispose(){}
}

[LIBGDX] SplashScreen

Posted by : Unknown 0 Comments

- Copyright © BLOG GUE WANGI - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -