ZGDanmaku

This is an android library which use opengles 2.0 to renderer danmaku effect.

初衷/Introduction

在Github上能找到很多开源的弹幕库,并且有很多是优秀的实现,基本上能够满足大众的需求,但是我却找不到使用opengles实现渲染的。于是我就自己着手学习一下opengles,并简单实现了一个弹幕。

效果/Demo

alt demo

Powering in YY:

alt yy

实现原理/Understanding Android OpenGLES

使用/Usage

<org.zhgeaits.zgdanmaku.view.ZGDanmakuView
        android:id="@+id/danmaku"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
IZGDanmakuView danmakuView = (IZGDanmakuView) findViewById(R.id.danmaku);
danmakuView.setSpeed(100);//设置弹幕速度,单位px/s
danmakuView.setLines(24);//设置弹幕行数
danmakuView.setLeading(2);//设置行距

danmakuView.start();
for (int i = 0; i < 1000; i ++) {
    danmakuView.shotTextDanmamku("hello world!");
}

Button closeSwitcher = (Button) findViewById(R.id.openOrClose);
closeSwitcher.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(danmakuView.isHide()) {
            danmakuView.show();
        } else {
            danmakuView.hide();
        }
    }
});

Button pauseSwitcher = (Button) findViewById(R.id.pauseOrResume);
pauseSwitcher.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(danmakuView.isPause()) {
            danmakuView.resume();
        } else {
            danmakuView.pause();
        }
    }
});

TODO

1.修改弹幕逻辑

2.修改为时间同步策略

Dependencies

1.由于glsurfaceview不能介于view的中间层,要么底层,要么顶层,是做不到处于中间层,然后透明的,所以需要使用TextureView。

GLTextureView:

2.使用了DanmakuFlameMaster的创建bitmap方法

License

Copyright (C) 2016 Zhang Ge <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.