我想在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;
答案 0 :(得分:1)
int centerX = canvas.getWidth() / 2; //Gets exact center from left to right
int centerY = canvas.getHeight() / 2; //Gets exact center from top to bottom