Я создал для себя класс спрайтов на пикселях для простой игры в java и swing, и я не хочу, чтобы некоторые спрайты проходили через другие спрайты. Поэтому я написал две петли, которые должны добавить пиксели каждого другого спрайта в «материальный» массив уровня. Материал не должен быть проходимым. С уровнем он действительно работает. Там спрайт не может пройти через его материал. Но с другими спрайтами это не так. Он может пройти через них. И это ошибка, которую я действительно хочу исправить. Похоже, что пиксельные массивы спрайтов не добавлены.Java swing 2D-пиксельный класс спрайтов не работает правильно
Любая помощь очень ценится!
Код:
int applied_pixels=lvl.material.length;
Sprite[] others=new Sprite[] {other sprites};
/*EDIT : others[i].frameborders[others[i].frame].all is the point array of the sprites' pixels
others[i].frame is the frame of the sprite object, because they contain an array of BufferedImages. Frame is the one that should be taken*/
Level lvl=the level; //Containing a couple of point arrays of pixels of some types, for example containing the material array of pixels
int apply_pixels=0; //How many pixels are needed ?
for (int i=0; i < others.length; i++) {
if (others[i] != null) { //Isn't the sprite null
apply_pixels=apply_pixels+others[i].frameborders[others[i].frame].all.length; //How many points does it has to add ?
}
}
level=lvl.clone(); //Copy level to be able to later append points to the material array
level.material=new Point[apply_pixels];
System.arraycopy(lvl.material,0,level.material,0,lvl.material.length); //Copy old material array points
int appending_position=0;
appending_position=lvl.material.length; //Which destination position to append the points at ?
for (int i=0; i < others.length; i++) {
if (others[i] != null) { //Isn't the sprite null
System.arraycopy(others[i].frameborders[others[i].frame].all,0,level.material,appending_position,others[i].frameborders[others[i].frame].all.length); //Copy the points from the sprite to the material array
appending_position=appending_position+others[i].frameborders[others[i].frame].all.length; //Position to append at is now plus the length of appended points
}
}
Без какого-либо контекста код, который вы отправили, совершенно бессмыслен. Например, мы понятия не имеем, как вы вычисляете столкновений, где и возникает реальная проблема. –
Я хотел дать понять: проблемы там нет. Потому что тогда он не будет работать с точками уровня. – user7185318
Проблема заключается в том, что точки должны быть добавлены, но из-за возможной ссылки или чего-то еще они не кажутся. – user7185318