如何使Android动态壁纸与LibGDx

如何使Android动态壁纸与LibGDx

本文介绍了如何使Android动态壁纸与LibGDx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要让的Andr​​oid 动态壁纸使用 LibGDx 。我创建了以下从

的Eclipse 显示错误:

的方法 createListener()类型 MainActivity 必须重写或实现的超类型的方法​​

的方法 createConfig()类型 MainActivity 必须重写或实现的超类型的方法​​

和报价删除 @覆盖注释。哪里是我的错?

我的code:

 公共类MainActivity扩展AndroidLiveWallpaperService {@覆盖
公共ApplicationListener createListener(){
    返回新壁纸();
}@覆盖
公共AndroidApplicationConfiguration createConfig(){
    返回新AndroidApplicationConfiguration();
}@覆盖
公共无效offsetChange(ApplicationListener监听器,浮动xOffset,浮yOffset,浮xOffsetStep,浮yOffsetStep,
    INT xPixelOffset,诠释yPixelOffset){
    Gdx.app.log(LiveWallpaper,偏移量改为:+ xOffset +,+ yOffset);
}

}


解决方案

这似乎对LiveWallpapers维基已经过时o.o(我要去检查)。这是我做的方式:

MainActivity.java

 包com.zoryth.blockslw;进口com.badlogic.gdx.ApplicationListener;
进口com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
进口com.badlogic.gdx.backends.android.AndroidLiveWallpaperService;
进口com.badlogic.gdx.backends.android.AndroidWallpaperListener;公共类MainActivity扩展AndroidLiveWallpaperService {
    公共静态浮动pixelOffset,用于= 0;    @覆盖
    公共无效onCreateApplication(){
        super.onCreateApplication();        最后AndroidApplicationConfiguration配置=新AndroidApplicationConfiguration();
        config.useGL20 = FALSE;
        config.useCompass = FALSE;
        config.useWakelock = FALSE;
        config.useAccelerometer = FALSE;
        config.getTouchEventsForLiveWallpaper = TRUE;        最后ApplicationListener监听器=新WallpaperListener();
        初始化(监听器,配置);
    }    公共静态类WallpaperListener扩展BlocksLW实现AndroidWallpaperListener {
        @覆盖
        公共无效创建(){
            super.resolver =新解析器(){
                @覆盖
                公众持股量getxPixelOffset(){
                    返回pixelOffset,用于;
                }
        };            super.create();
        };        / *
         *从不使用xOffset / yOffset和xOffsetStep / yOffsetStep,因为定制的发射将与您的混乱
         *大脑和这个问题无法修复!只使用xPixelOffset / yPixelOffset(谁使用yPixelOffset ???)))
         * /        @覆盖
        公共无效offsetChange(浮动xOffset,浮yOffset,浮xOffsetStep,浮yOffsetStep,诠释xPixelOffset,诠释yPixelOffset){
            pixelOffset,用于= xPixelOffset;
        }        @覆盖
        公共无效previewStateChange(布尔值是preVIEW){
        }
    }
}

BlocksLW 是我的应用程序监听器的核心项目)

这是Semtiko LW模板。我根据我的code,主要看它,我建议你给它一个检查;)

I want to make Android Live Wallpaper using LibGDx. I created the project following the instructions from this github link

but Eclipse show error:

"The method createListener() of typeMainActivity must override or implement a supertype method"

"The method createConfig() of type MainActivity must override or implement a supertype method"

and offers remove @Override annotation. Where is my mistake?

My code:

public class MainActivity extends AndroidLiveWallpaperService {

@Override
public ApplicationListener createListener() {
    return new Wallpaper();
}

@Override
public AndroidApplicationConfiguration createConfig () {
    return new AndroidApplicationConfiguration();
}

@Override
public void offsetChange (ApplicationListener listener, float xOffset, float yOffset, float xOffsetStep, float yOffsetStep,
    int xPixelOffset, int yPixelOffset) {
    Gdx.app.log("LiveWallpaper", "offset changed: " + xOffset + ", " + yOffset);
}

}

解决方案

It seems the wiki about LiveWallpapers is outdated o.o (I'm gonna check that). This is the way I do it:

MainActivity.java

package com.zoryth.blockslw;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.badlogic.gdx.backends.android.AndroidLiveWallpaperService;
import com.badlogic.gdx.backends.android.AndroidWallpaperListener;

public class MainActivity extends AndroidLiveWallpaperService{
    public static float pixelOffset = 0;

    @Override
    public void onCreateApplication () {
        super.onCreateApplication();

        final AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.useGL20 = false;
        config.useCompass = false;
        config.useWakelock = false;
        config.useAccelerometer = false;
        config.getTouchEventsForLiveWallpaper = true;

        final ApplicationListener listener = new WallpaperListener();
        initialize(listener, config);
    }

    public static class WallpaperListener extends BlocksLW implements AndroidWallpaperListener {
        @Override
        public void create() {
            super.resolver = new Resolver() {
                @Override
                public float getxPixelOffset() {
                    return pixelOffset;
                }
        };

            super.create();
        };

        /*
         * never use xOffset/yOffset and xOffsetStep/yOffsetStep, because custom launchers will mess with your
         * brain and this problem can't be fixed! Use only xPixelOffset/yPixelOffset (who used yPixelOffset???)))
         */

        @Override
        public void offsetChange (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
            pixelOffset = xPixelOffset;
        }

        @Override
        public void previewStateChange (boolean isPreview) {
        }
    }
}

(BlocksLW is my App Listener in the core project)

This is a very good Template made by Semtiko LW Template. I based my code mostly on it, I recommend you to give it a check ;)

这篇关于如何使Android动态壁纸与LibGDx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:41