Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DanmakuItem.willHit()有问题 #10

Open
jiaoyang623 opened this issue Jun 29, 2017 · 2 comments
Open

DanmakuItem.willHit()有问题 #10

jiaoyang623 opened this issue Jun 29, 2017 · 2 comments

Comments

@jiaoyang623
Copy link

如果这个item没有被draw,它的mContainerWidth就是0,这导致willHit()总是返回true。一条航道只能画一个弹幕。

    public boolean willHit(IDanmakuItem runningItem) {
        if (runningItem.getWidth() + runningItem.getCurrX() > mContainerWidth) {
            return true;
        }

        if (runningItem.getSpeedFactor()>= mFactor) {
            return false;
        }

        float len1 = runningItem.getCurrX() + runningItem.getWidth();
        float t1 = len1 / (runningItem.getSpeedFactor() * DanmakuItem.sBaseSpeed);
        float len2 = t1 * mFactor * DanmakuItem.sBaseSpeed;
        if (len2 > len1) {
            return true;
        } else {
            return false;
        }

    }
@jiaoyang623
Copy link
Author

建议写法是在调用willHit的时候把控件宽度传进来

if (!item.willHit(di, getWidth())) {
    return (i + ind) % mMaxRow;
}

修改接口willHit(IDanmakuItem runningItem, int viewWidth)和实现

    public boolean willHit(IDanmakuItem runningItem, int viewWidth) {
        // 修改成viewWidth*0.95是因为需要保持两条弹幕的间距
        if (runningItem.getWidth() + runningItem.getCurrX() > viewWidth * 0.95) {
            return true;
        }

        if (runningItem.getSpeedFactor() >= mFactor) {
            return false;
        }

        float len1 = runningItem.getCurrX() + runningItem.getWidth();
        float t1 = len1 / (runningItem.getSpeedFactor() * DanmakuItem.sBaseSpeed);
        float len2 = t1 * mFactor * DanmakuItem.sBaseSpeed;
        if (len2 > len1) {
            return true;
        } else {
            return false;
        }

    }

@Reone
Copy link

Reone commented Feb 25, 2020

Yes i found this too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants