Vote count:
0
This is the Core project :
public class GameClass extends Game {
public CustomScreen customScreen;
public CustomScreen currentScreen;
public CustomInterface handler;
public static int screenWidth;
public static int screenHeight;
public GameClass(CustomInterface handler) {
this.handler = handler;
}
@Override
public void create () {
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
customScreen = new CustomScreen();
currentScreen = customScreen;
setScreen(currentScreen);
handler.PickFile();
}
public void onPickFile(String filePath) {
currentScreen.onPickFile(filePath);
}
}
public class CustomObject {
public Texture texture;
public CustomObject() {
this.texture = new Texture(Gdx.files.internal("badlogic.jpg"));
}
public void Display(SpriteBatch batcher) {
batcher.draw(texture, 0, 0, 500, 500);
}
}
public interface CustomInterface {
public void PickFile();
}
public class CustomScreen implements Screen {
Texture texture = new Texture(Gdx.files.internal("badlogic.jpg"));
SpriteBatch batcher;
OrthographicCamera cam;
CustomObject obj2;
public CustomScreen() {
cam = new OrthographicCamera();
cam.setToOrtho(true, GameClass.screenWidth, GameClass.screenHeight);
batcher = new SpriteBatch();
batcher.setProjectionMatrix(cam.combined);
}
public void onPickFile(String filePath) {
obj2 = new CustomObject();
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batcher.begin();
if (obj2 != null)
obj2.Display(batcher);
batcher.end();
}
}
And this is the Android project :
public class AndroidLauncher extends AndroidApplication implements CustomInterface {
GameClass game;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
game = new GameClass(this);
initialize(game, config);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
game.onPickFile("");
}
public void PickFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
}
When the render function in the CustomScreen class is called, instead of displaying the badlogic.jpg texture I was expecting, it displays a black texture.
(I know part of the code in the Android project is useless and that I could basically load the badlogic.jpg texture in the Core project, but in the end the point is to load a texture picked from the Android library, but as you can see, I can't even load a texture in the asset folder yet)
I've been trying to fix this for several months now, and I still have no idea how to do it, please help me !
asked 59 secs ago
Can't load Texture in onActivityResult
Aucun commentaire:
Enregistrer un commentaire