package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array;
public class MyGdxGame extends ApplicationAdapter {
private Music music;
private Texture playerTexture, platformTexture;
private JumpPlayer player;
private Array<Platform> PlatformArray;
SpriteBatch batch;
@Override
public void create () {
batch = new SpriteBatch();
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.end();
}
}
I dwie klasy:
package com.mygdx.game.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
public class JumpPlayer extends Rectangle {
private Sound jumpSound;
private Texture texture;
public boolean canJump = true;
public float jumpVelocity;
public JumpPlayer(Texture texture){
this.texture = texture;
this.height = texture.getHeight();
this.width = texture.getWidth();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("cd581.mp3"));
}
public void draw(SpriteBatch batch){
batch.draw(texture, x, y);
}
public void jump(){
if(canJump && jumpVelocity >= - 100){
jumpVelocity += 800;
canJump = false;
jumpSound.play();
}
}
}
package com.mygdx.game.desktop;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
public class Platform extends Rectangle{
private Texture texture;
public Platform(Texture texture){
this.texture = texture;
this.height = texture.getHeight();
this.width = texture.getWidth();
}
public void draw(SpriteBatch batch){
batch.draw(texture, x, y);
}
}
pokolorowałem, bogdans