设为首页 加入收藏

TOP

【Android】用Cubism 2制作自己的Live2D——来制作动态壁纸吧!(二)
2019-09-01 23:13:21 】 浏览:57
Tags:Android Cubism 制作 自己 Live2D 动态 壁纸
i = 0 ; i < TEXTURE_PATHS.length ; i++ ) 19 { 20 InputStream in = mngr.open( TEXTURE_PATHS[i] ) ; 21 int texNo = UtOpenGL.loadTexture(gl , in , true ) ; 22 live2DModel.setTexture( i , texNo ) ; 23 in.close(); 24 } 25 } 26 catch (IOException e) 27 { 28 e.printStackTrace(); 29 } 30 31 try 32 { 33 InputStream in = mngr.open( MOTION_PATH ) ; 34 motion = Live2DMotion.loadMotion( in ) ; 35 in.close() ; 36 37 in=mngr.open(PHYSICS_PATH); 38 physics=L2DPhysics.load(in); 39 in.close(); 40 } 41 catch (Exception e) 42 { 43 e.printStackTrace(); 44 } 45 }

这个就是用流加载Assets文件夹里的文件到需要他的地方了,与上一篇差别不大,多了Motion和Physics的载入,方法也是一样的。

 



 

onSurfaceChanged(GL10 gl, int width, int height)-

public void onSurfaceChanged(GL10 gl, int width, int height) {
        
        gl.glViewport( 0 , 0 , width , height ) ;

        
        gl.glMatrixMode( GL10.GL_PROJECTION ) ;
        gl.glLoadIdentity() ;

        float modelWidth = live2DModel.getCanvasWidth();
        
        gl.glOrthof(
                0 ,
                modelWidth ,
                modelWidth * height / width,
                0 ,
                0.5f ,    -0.5f 
                ) ;

        glWidth=width;
        glHeight=height;
    }
View Code

也是没什么变化,不过这次我在中文说明书中找到了对这些绘制参数的描述

 



 

 

LiveWallpaperService类-

/*这个GLWallPaperService类是动态壁纸的基础类,此类为壁纸项目的开发提供了服务接口,通过集成GLWallPaperService类,重写onCreateEngine()等方法实现壁纸功能*/
public class LiveWallpaperService extends GLWallpaperService {
    public Engine onCreateEngine() {}
    class MyEngine extends GLEngine {
        public MyEngine() {}
//获取触摸事件
        public void onTouchEvent(MotionEvent event) {}
  }
}

壁纸类的结构就是这样的,下面是完整代码。

 1 public class LiveWallpaperService extends GLWallpaperService {
 2     public LiveWallpaperService() {
 3         super();
 4     }
 5 
 6     public Engine onCreateEngine() {
 7         MyEngine engine = new MyEngine();
 8         return engine;
 9     }
10 
11     class MyEngine extends GLEngine {
12         Live2DRenderer renderer;
13 
14         public MyEngine() {
15             super();
16             // handle prefs, other initialization
17             renderer = new Live2DRenderer(getApplicationContext());
18             setRenderer(renderer);
19             setRenderMode(RENDERMODE_CONTINUOUSLY);
20         }
21 
22         @Override
23         public void onTouchEvent(MotionEvent event) {
24             switch (event.getAction()) {
25             case MotionEvent.ACTION_DOWN:
26                 break;
27             case MotionEvent.ACTION_UP:
28                 renderer.resetDrag();
29                 break;
30             case MotionEvent.ACTION_MOVE:
31                 renderer.drag(event.getX(), event.getY());
32                 break;
33             case MotionEvent.ACTION_CANCEL:
34                 break;
35             }
36         }
37 
38         public void onDestroy() {
39             super.onDestroy();
40             if (renderer != null) {
41                 renderer.release();
42             }
43             renderer = null;
44         }
45     }
46 }

 



 

下面就是我自己尝试的结果了:

 

 

-

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于静态注册BroadcastReceiver接.. 下一篇Android调试神器stetho使用详解和..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目