I show the example code and ask the question.
ArrayList<Nave> naves;
int tiempo;
void settings(){
size(640,480,P2D);
noSmooth();
}
void setup(){
frameRate(60);
rectMode(CENTER);
naves = new ArrayList<Nave>();
}
void draw(){
background(0,0,0);
//crear objetos cada tiempo
tiempo++;
if(tiempo >= 120){
naves.add(new Nave());
tiempo = 0;
}
//actualizar,pintar
for(int indice = naves.size()-1;indice >= 0;indice--){
Nave nave = naves.get(indice);
nave.actualizar();
nave.pintar();
}
//texto
textSize(24);
textAlign(CENTER);
fill(color(255,255,255));
text("tiempo: "+tiempo,320,32);
}
public class Nave{
private float x,y,ancho,alto,velocidad;
private color colores;
public Nave(){
this.ancho = 50;
this.alto = 50;
this.x = random(32,608);
this.y = random(-32,-608);
this.velocidad = 3;
this.colores = color(225,225,0);
}
public void actualizar(){
mover();
eliminar();
}
private void pintar(){
fill(colores);
rect(x,y,ancho,alto);
}
private void mover(){
y += velocidad;
}
private void eliminar(){
if(y > 440){
naves.remove(this);
}
}
}//fim clase nave
This example shows some objects that appear at the top and move down.I would like to know how a coordinate path could be created and the objects would move along that path.
I thought that you could create two lists and add the “x” coordinates in one list and the “y” coordinates in another list. Then the object would have to traverse those coordinates at a set speed. Do you know how I could do this because I have no idea, Although if you have another idea I would be happy to read it.