我想在Android屏幕上绘制粒子的中心

这是代码:

private void drawParticles(Canvas canvas) {
    if (tween >= 1.0f) {
        int i = currentScene + 1;
        currentScene = i;
        currentScene = i % numScene;
    }
    frameStart = (particles.length * currentScene) / numScene;
    frameEnd = (particles.length * (currentScene + 1)) / numScene;
    i = frameStart;
    while (i < frameEnd) {
        particles[i].step(tween);
        particles[i].draw(canvas);
        i++;
    }
    if (tween >= 1.0f) {
        tween = 0.0f;
    }
    tween += factor;
}


我使用此代码成功地在屏幕的底部中心绘制了粒子,但我想使粒子位置从左到右和从上到下精确居中

以及如何使用此公式:

frameStart = (particles.length * currentScene) / numScene;
frameEnd = (particles.length * (currentScene + 1)) / numScene;

最佳答案

int centerX = canvas.getWidth() / 2; //Gets exact center from left to right
int centerY = canvas.getHeight() / 2; //Gets exact center from top to bottom

07-26 02:12