More help on the animation code?
in
Programming Questions
•
2 years ago
Hi guys
can you help me to apply the following changes in the codes below.....>>
<<
import ijeoma.motion.*;
import ijeoma.motion.tween.*;
import ijeoma.motion.event.*;
Bus myBus;
Road myRoad;
Tween t;
void setup() {
size(500,500);
Motion.setup(this);
myBus = new Bus();
myRoad = new Road();
t = new Tween();
t.setName("car");
t.addParameter(new Parameter(myBus, "x", 0, width));
t.setDuration(100);
t.play();
t.repeat();
}
void draw() {
background(255);
myRoad.display();
myBus.display();
}
void keyPressed() {
if(key == 'b')
if(t.isPlaying)
t.pause();
else
t.resume();
}
void tweenEnded(Tween _t) {
if(_t.getName().equals("car")) {
myBus.y = myRoad.y += 50;
myRoad.tp.play();
}
}
public class Bus {
public float x, y = 0;
Bus() {
}
void display() {
fill(255,0,0); //drawing the bus
stroke(0);
rect(x, y, 100, 40);
fill(0);
ellipse(x+25, y+40, 20, 20);
ellipse(x+75, y+40, 20, 20);
}
}
public class Road {
float x, y = 0;
float w = width;
float h = 50;
int stripeCount = 10;
float stripW = (width)/stripeCount;
float stripH = 10;
int stripGap = 10;
TweenParallel tp;
Road() {
tp = new TweenParallel();
for(int i = -1; i < stripeCount; i++)
tp.addChild(new Tween((i+1)*(stripW+stripGap), i*(stripW+stripGap), 100));
tp.play();
}
void display() {
fill(255);
rect(x,y,width,50);
fill(0);
for(int i = 0; i < tp.getChildCount(); i++)
rect(tp.getChild(i).getPosition(), y + (h/2 - stripH/2), stripW, stripH);
}
}
can you help me to apply the following changes in the codes below.....>>
How can I make the road not moving at all? because I can see that there's a bug when I press 'b' and the road keeps moving for couple seconds and then stops. And also what if I want the roads to be drawn parallel roads first? I want them just to look static, and be part of the visualization...
And when I hold the 'b' button down, it constantly switches between moving and stopping the car. How can I incorporate keyReleased() instead of keyPressed() so that it only toggles the motion once when I press 'b' regardless of how long you decide to keep it down?
And when I hold the 'b' button down, it constantly switches between moving and stopping the car. How can I incorporate keyReleased() instead of keyPressed() so that it only toggles the motion once when I press 'b' regardless of how long you decide to keep it down?
<<
import ijeoma.motion.*;
import ijeoma.motion.tween.*;
import ijeoma.motion.event.*;
Bus myBus;
Road myRoad;
Tween t;
void setup() {
size(500,500);
Motion.setup(this);
myBus = new Bus();
myRoad = new Road();
t = new Tween();
t.setName("car");
t.addParameter(new Parameter(myBus, "x", 0, width));
t.setDuration(100);
t.play();
t.repeat();
}
void draw() {
background(255);
myRoad.display();
myBus.display();
}
void keyPressed() {
if(key == 'b')
if(t.isPlaying)
t.pause();
else
t.resume();
}
void tweenEnded(Tween _t) {
if(_t.getName().equals("car")) {
myBus.y = myRoad.y += 50;
myRoad.tp.play();
}
}
public class Bus {
public float x, y = 0;
Bus() {
}
void display() {
fill(255,0,0); //drawing the bus
stroke(0);
rect(x, y, 100, 40);
fill(0);
ellipse(x+25, y+40, 20, 20);
ellipse(x+75, y+40, 20, 20);
}
}
public class Road {
float x, y = 0;
float w = width;
float h = 50;
int stripeCount = 10;
float stripW = (width)/stripeCount;
float stripH = 10;
int stripGap = 10;
TweenParallel tp;
Road() {
tp = new TweenParallel();
for(int i = -1; i < stripeCount; i++)
tp.addChild(new Tween((i+1)*(stripW+stripGap), i*(stripW+stripGap), 100));
tp.play();
}
void display() {
fill(255);
rect(x,y,width,50);
fill(0);
for(int i = 0; i < tp.getChildCount(); i++)
rect(tp.getChild(i).getPosition(), y + (h/2 - stripH/2), stripW, stripH);
}
}
1