本文将分享适用于Android的libGDX动画的详细内容,并且还将对android的动画有哪些进行详尽解释,此外,我们还将为大家带来关于Android/Libgdx:检测多任务按钮、android–
本文将分享适用于Android的libGDX动画的详细内容,并且还将对android的动画有哪些进行详尽解释,此外,我们还将为大家带来关于Android / Libgdx:检测多任务按钮、android – libgdx background图像更改、android – LibGDX gdx-freetype BlueStacks、android – libGDX IntelliJ IDEA无法访问com.badlogic.gdx.Application的相关知识,希望对你有所帮助。
本文目录一览:- 适用于Android的libGDX动画(android的动画有哪些)
- Android / Libgdx:检测多任务按钮
- android – libgdx background图像更改
- android – LibGDX gdx-freetype BlueStacks
- android – libGDX IntelliJ IDEA无法访问com.badlogic.gdx.Application
适用于Android的libGDX动画(android的动画有哪些)
如果我为桌面启动它,它运行得很好,但是为我的Android导出后,它在我启动该应用程序后立即崩溃。
所以我的问题…:
它适用于台式机而不适用于我的Android有什么问题?
public class Player implements Serializable{/** * */private static final long serialVersionUID = -7913517465400462738L;Vector2 position;private static final int col = 4;private static final int row = 4;private Animation animation;private Texture playerTexture;private TextureRegion[] frames;private TextureRegion currentFrame;private float stateTime;private int x,y, deltaX, deltaY;public Player(Vector2 position){ this.position = position; playerTexture = new Texture(Gdx.files.internal("Charackter/charackter_sprite.png")); TextureRegion[][] temp = TextureRegion.split(playerTexture, playerTexture.getWidth() / col, playerTexture.getHeight() / row); frames = new TextureRegion[col* row]; int index = 0; for(int i = 0; i < row; i++){ for(int j = 0; j < col; j++){ frames[index++] = temp[i][j]; } } animation = new Animation(1, frames); stateTime = 0; currentFrame = animation.getKeyFrame(0); deltaX = Gdx.graphics.getWidth(); deltaY = Gdx.graphics.getHeight();}public void update(){ if(stateTime < 4){ stateTime += Gdx.graphics.getDeltaTime(); } else{ stateTime = 0; } if (Gdx.input.isTouched()) { x = Gdx.input.getX(); y = Gdx.input.getY(); if(x < deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){ position.x -= 1; currentFrame = animation.getKeyFrame(4 + stateTime); } if(x > deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){ position.x += 1; currentFrame = animation.getKeyFrame(8 + stateTime); } if(y < deltaY * 35 / 100 ){ position.y += 1; currentFrame = animation.getKeyFrame(12 + stateTime); } if(y > deltaY * 65 / 100 ){ position.y -= 1; currentFrame = animation.getKeyFrame(0 + stateTime); } }}public Vector2 getPosition() { return position;}public void setPosition(Vector2 position) { this.position = position;}public TextureRegion getCurrentFrame() { return currentFrame;}}
。
public class PlayScreen implements Screen {private SpriteBatch batch;private Vector2 position;private Game game;private Player player;private Texture bild;public PlayScreen(Game game){ this.game = game;}@Overridepublic void render(float delta) { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); player.update(); batch.begin(); batch.draw(player.getCurrentFrame(), player.getPosition().x, player.getPosition().y); batch.end();}@Overridepublic void resize(int width, int height) { // TODO Auto-generated method stub}@Overridepublic void show() { batch = new SpriteBatch(); position = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); player = new Player(position); bild = new Texture("spongebob.png");}@Overridepublic void hide() { // TODO Auto-generated method stub}@Overridepublic void pause() { // TODO Auto-generated method stub}@Overridepublic void resume() { // TODO Auto-generated method stub}@Overridepublic void dispose() { batch.dispose();}}
Logcat
11-25 11:25:20.990: D/dalvikvm(862): Trying to load lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad5011-25 11:25:21.040: D/dalvikvm(862): Added shared lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad5011-25 11:25:21.040: D/dalvikvm(862): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50, skipping init11-25 11:25:21.100: D/AndroidRuntime(862): Shutting down VM11-25 11:25:21.100: W/dalvikvm(862): threadid=1: thread exiting with uncaught exception (group=0xb1a73d70)11-25 11:25:21.110: E/AndroidRuntime(862): FATAL EXCEPTION: main11-25 11:25:21.110: E/AndroidRuntime(862): Process: com.mygdx.game.android, PID: 86211-25 11:25:21.110: E/AndroidRuntime(862): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.011-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread.access$800(ActivityThread.java:138)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)11-25 11:25:21.110: E/AndroidRuntime(862): at android.os.Handler.dispatchMessage(Handler.java:102)11-25 11:25:21.110: E/AndroidRuntime(862): at android.os.Looper.loop(Looper.java:136)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread.main(ActivityThread.java:5026)11-25 11:25:21.110: E/AndroidRuntime(862): at java.lang.reflect.Method.invokeNative(Native Method)11-25 11:25:21.110: E/AndroidRuntime(862): at java.lang.reflect.Method.invoke(Method.java:515)11-25 11:25:21.110: E/AndroidRuntime(862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)11-25 11:25:21.110: E/AndroidRuntime(862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)11-25 11:25:21.110: E/AndroidRuntime(862): at dalvik.system.NativeStart.main(Native Method)11-25 11:25:21.110: E/AndroidRuntime(862): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.011-25 11:25:21.110: E/AndroidRuntime(862): at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)11-25 11:25:21.110: E/AndroidRuntime(862): at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)11-25 11:25:21.110: E/AndroidRuntime(862): at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)11-25 11:25:21.110: E/AndroidRuntime(862): at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)11-25 11:25:21.110: E/AndroidRuntime(862): at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)11-25 11:25:21.110: E/AndroidRuntime(862): at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.Activity.performCreate(Activity.java:5242)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)11-25 11:25:21.110: E/AndroidRuntime(862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)11-25 11:25:21.110: E/AndroidRuntime(862): ... 11 more
我是Java的新手,所以我希望它是正确的部分:x
答案1
小编典典有一些人例外,logcat说:
GdxRuntimeException: Libgdx requires OpenGL ES 2.0
这是由于您的模拟器未将gpu用于图形处理,最好的解决方案是使用手机来测试您的应用程序
由于某些原因(可能是opengl不能出错),以下错误的解决方案也可能会帮助您
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: xxx.xxx
如果只有在Windows下可以在Android上进行实验时才遇到此错误,则可能是因为其中一项资产与您在代码中使用的名称不完全匹配。Unix区分大小写,因此image.jpg与Image.jpg不同。因此,请检查您所需要的每项资产,以确保名称匹配!
Android / Libgdx:检测多任务按钮
我正在使用Screen类,只有在应用程序有效更改时才会调用pause()方法.我没有设法检测按钮事件作为解决方法.
谢谢你的帮助.
解决方法
你想要监听的密钥是KEYCODE_APP_SWITCH.如果没有使用InputAdapter(我不知道相关的Keys值,如果它甚至存在),那么你需要查看gdx并查看原因它没有通过.
android – libgdx background图像更改
问题:通过堆栈上的Table对象将 Image加载到舞台后,将图像引用更改为不同的图像. Stage.draw()不关心它是否制作了原始图像的副本.我想将背景保持为Image类并通过stage.draw()进行渲染.
更复杂的是,如果我在render()方法中将图像更改为另一个图像,则image.setVisible(false)也会停止工作.
public class TestScreen extends AbstractScreen { private Stage stage; private Image background; private boolean ChangeBackground = true; private final float refreshTime = 2.0f; // refresh to new image every 2 seconds. private float counter = refreshTime; public TestScreen(Game game) { super(game); } @Override public void render(float deltaTime) { Gdx.gl.glClearColor(0.0f,0.0f,1.0f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); if(ChangeBackground){ counter -= deltaTime; if(counter < 0){ counter = refreshTime; // Assets class has the 12 images loaded as "Image" objects already. // I simple want to change the reference to other (already loaded in memory images) ... // and make stage render the new image. background = Assets.instance.wallpapers[(int) (Math.random()*12)]; // The image should change. //background.setVisible(false); } } stage.act(deltaTime); stage.draw(); } @Override public void resize(int width,int height) { stage.setViewport(Constants.VIEWPORT_GUI_WIDTH,Constants.VIEWPORT_GUI_HEIGHT,false); } @Override public void show() { stage = new Stage(); Gdx.input.setInputProcessor(stage); makeStage(); } @Override public void hide() { stage.dispose(); } @Override public void pause() { } // Builds the Background later and adds it to a stage through a stack. // This is how it''s done in my game. I made this test bench to demonstrate. private void makeStage() { Table BackGroundLayer = new Table(); background = Assets.instance.wallpapers[(int) (Math.random()*12)]; BackGroundLayer.add(background); Stack layers = new Stack(); layers.setSize(800,480); layers.add(BackGroundLayer); stage.clear(); stage.addActor(layers); }
}
解决方法
什么是Drawable?它是实现Drawable接口的任何类,例如TextureRegionDrawable.如果您使用的是TextureRegions,则可以使用此构造函数:TextureRegionDrawable(TextureRegion region);.也许将背景图像存储在可绘制数组中会更好,这样每次设置新的Drawable时都不必调用construcor.示例代码:
TextureRegionDrawable[] images = new TextureRegionDrawable[12]; for (int i = 0; i<12; i++) { images[i] = new TextureRegionDrawable(Assets.instance.textureRegions[i]); }
然后在你的渲染中:
if(changeBackground) { counter -= delta; if (counter < 0) { counter = refreshtime background.setDrawable(images[(int)(Math.random()*12)]); } }
这应该工作
android – LibGDX gdx-freetype BlueStacks
但仍然:
11-08 21:14:10.280: E/AndroidRuntime(1378): FATAL EXCEPTION: GLThread 9 11-08 21:14:10.280: E/AndroidRuntime(1378): com.badlogic.gdx.utils.GdxRuntimeException: Couldn''t load shared library ''gdx-freetype'' for target: Linux,32-bit 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:110) 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.badlogic.gdx.graphics.g2d.freetype.FreeType.initFreeType(FreeType.java:541) 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>(FreeTypeFontGenerator.java:64) 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.axl.where.test.create(test.java:153) 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:334) 11-08 21:14:10.280: E/AndroidRuntime(1378): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1356) 11-08 21:14:10.280: E/AndroidRuntime(1378): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118) 11-08 21:14:10.280: E/AndroidRuntime(1378): Caused by: java.lang.UnsatisfiedLinkError: Couldn''t load gdx-freetype: findLibrary returned null 11-08 21:14:10.280: E/AndroidRuntime(1378): at java.lang.Runtime.loadLibrary(Runtime.java:429) 11-08 21:14:10.280: E/AndroidRuntime(1378): at java.lang.System.loadLibrary(System.java:554) 11-08 21:14:10.280: E/AndroidRuntime(1378): at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:106) 11-08 21:14:10.280: E/AndroidRuntime(1378): ... 6 more
有任何想法吗 ? LibGDX 0.9.9
解决方法
http://libgdx.badlogicgames.com/nightlies/dist/extensions/gdx-freetype/x86/
另外,你正在使用v0.9.6文件o.O使用nightlies:
http://libgdx.badlogicgames.com/nightlies/dist/extensions/gdx-freetype/
android – libGDX IntelliJ IDEA无法访问com.badlogic.gdx.Application
项目在 Eclipse中运行良好,但是当我在 Android Studio中导入它时,
android项目MainActivity.java抛出4个异常:
java: cannot access com.badlogic.gdx.Application class file for com.badlogic.gdx.Application not found java: cannot find symbol symbol: variable super location: class com.vestrel00.nekko.MainActivity java: cannot find symbol symbol: method initialize(com.vestrel00.nekko.KFNekko,com.badlogic.gdx.backends.android.AndroidApplicationConfiguration) location: class com.vestrel00.nekko.MainActivity java: method does not override or implement a method from a supertype
有没有人有办法解决吗?
解决方法
解:
右键单击项目>打开模块设置>图书馆>小绿色按钮(新项目库Alt插入)> Java>然后选择libGdx.jar文件.之后,您必须将此库包含在桌面和Android项目中.
不要关闭窗口,选择模块> android>依赖性> <小绿色按钮>模块依赖关系并选择主项目.对桌面执行相同操作并按确定. 就这样.我的所有项目现在都正常工作. 这是一个图片教程.它也解释了如何运行桌面项目. http://imgur.com/a/IBFIV
今天关于适用于Android的libGDX动画和android的动画有哪些的讲解已经结束,谢谢您的阅读,如果想了解更多关于Android / Libgdx:检测多任务按钮、android – libgdx background图像更改、android – LibGDX gdx-freetype BlueStacks、android – libGDX IntelliJ IDEA无法访问com.badlogic.gdx.Application的相关知识,请在本站搜索。
本文标签: