Java:在不通过处理刷新的情况下运行淡出动画的困难
我有一个简单的动画播放,当应用程序检测到锤子对象已达到某个角度时,圆圈向外缩放并淡出。但是,由于当前已实现,动画将只播放一次。我曾尝试使用for循环来允许动画完成,但这会导致整个应用程序在代码循环时暂停,而我所做的其他尝试均无效,因此,如果有任何帮助,将不胜感激Java:在不通过处理刷新的情况下运行淡出动画的困难,java,animation,processing,Java,Animation,Processing,我有一个简单的动画播放,当应用程序检测到锤子对象已达到某个角度时,圆圈向外缩放并淡出。但是,由于当前已实现,动画将只播放一次。我曾尝试使用for循环来允许动画完成,但这会导致整个应用程序在代码循环时暂停,而我所做的其他尝试均无效,因此,如果有任何帮助,将不胜感激 import oscP5.*; import netP5.*; OscP5 oscP5; NetAddress myRemoteLocation; float bx; float by; int boxSizeX = 160; in
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
float bx;
float by;
int boxSizeX = 160;
int boxSizeY = 30;
boolean overBox = true;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;
float angle = 4.70;
float cooldown;
int alphaVal = 255;
int colorchange = 0;
//for sound effect
float a = 0.0;
float s = 0.0;
BeatBall b1 = new BeatBall(210,425,60, 1);
BeatBall b2 = new BeatBall(570,395,60, 2);
Hammer h = new Hammer(135, -67, boxSizeY+25, boxSizeX-25, 1);
void setup()
{
ellipseMode(CENTER);
size(800, 600);
smooth();
frameRate(120);
bx = width/2.0;
by = height/2.0;
oscP5 = new OscP5(this,12001);
/* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
* an ip address and a port number. myRemoteLocation is used as parameter in
* oscP5.send() when sending osc packets to another computer, device,
* application. usage see below. for testing purposes the listening port
* and the port of the remote location address are the same, hence you will
* send messages back to this sketch.
*/
myRemoteLocation = new NetAddress("127.0.0.1",12000);
}
void draw()
{
background(0);
ellipseMode(CENTER);
float mx = constrain(angle, -2.6075916, -0.5207284);
///////////////////////////
//THIS IS THE ANIMATION //
//////////////////////////
if(locked)
{
a = a + 0.02;
s = cos(a)*10;
pushMatrix();
translate(210,425);
scale(s);
fill(colorchange, 30, 150, alphaVal);
ellipse(0, 0, 50, 50);
alphaVal = alphaVal - 3;
colorchange = colorchange + 3;
popMatrix();
}
pushMatrix();
translate(400, 425);
rotate(mx);
fill(222,223,255);
h.displayHammer();
rect(-25, -15, boxSizeX, boxSizeY);
popMatrix();
pushMatrix();
translate(595, 390);
rotate(radians(58));
fill(122,78,163);
rect(0, 0, 50, 50);
popMatrix();
b1.displayBall();
//b2.displaySquare();
cooldown = cooldown + 0.01;
println(cooldown);
if(mx == -2.6075916)
{
if(cooldown > 0.5)
{
locked = true;
soundEffect();
b1.collide();
cooldown = 0;
}
}
else if(mx == -0.5207284)
{
if(cooldown > 0.5)
{
b1.collide();
cooldown = 0;
}
}
}
void soundEffect()
{
}
void mousePressed()
{
xOffset = mouseX-bx;
yOffset = mouseY-by;
}
void mouseDragged()
{
angle = atan2(mouseY - 400, mouseX - 400);
println(angle);
}
你什么时候重置动画?抱歉,我应该澄清一下,现在动画没有结束,只是淡出以完成透明度。然后你必须重置动画。您希望动画何时重新开始?