Posted by : Unknown Rabu, 16 Januari 2019

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();
}

}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

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