Weird bug when loading spritesheets' sub-images #675
Replies: 5 comments
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2019-06-29 20:36:54
User: CalvinMT [] (age: 1451 days 🔥; posts: 114)
Hi!
I not sure if this bug is coming from my code or the LITIengine, that's why I'm posting it in this forum.
The bug happens rarely and randomly, and I couldn't find any way to reproduce it efficiently. Let me set an example.
I've got three files named
private void addLevels () {~~frame\_<name>\_unchecked.png
and three other files name[code]~~frame\_<name>\_checked.png
. They all look the same, except colorwise.Each of them have ten sub-images with numbers to reprent levels from 0 to 9.
Sometimes, or more rarely and randomly as said previously, in-game, one sub-image won't have the right color nor the right number.
Here's the only part of the code that deals with those sub-images:
`
this.nbOfLevelsInSelectedWorld = 0;
Resources.maps().getAll().stream().forEach(map -> {
if (map.getName().startsWith(this.worldSelect.getName().toLowerCase()) && this.nbOfLevelsInSelectedWorld < this.MAX_LEVELS_PER_WORLD) {
this.nbOfLevelsInSelectedWorld++;
}
});
this.listLevelsShowing.stream().forEach(level -> {
level.setVisible(false);
});
this.listLevelsHoveredImage.stream().forEach(hoveredImage -> {
hoveredImage.setVisible(false);
});
Image frameImageHovered = (Image) Resources.spritesheets().get("frame_" + this.worldSelect.getName().toLowerCase() + "hovered").getImage();
for (int i=0; i<this.nbOfLevelsInSelectedWorld; i++) {
Image frameImage;
switch (this.worldsData.get(this.worldSelect.getName()).getListLevelState().get(i)) {
case UNCHECKED:
frameImage = (Image) Resources.spritesheets().get("frame" + this.worldSelect.getName().toLowerCase() + "unchecked").getSprite(i);
break;
case CHECKED:
frameImage = (Image) Resources.spritesheets().get("frame" + this.worldSelect.getName().toLowerCase() + "_checked").getSprite(i);
break;
default:
frameImage = null;
break;
}
this.listLevelsShowing.get(i).setImage(frameImage);
this.listLevelsHoveredImage.get(i).setImage(frameImageHovered);
this.listLevelsShowing.get(i).setImageScaleMode(ImageScaleMode.FIT);
this.listLevelsHoveredImage.get(i).setImageScaleMode(ImageScaleMode.FIT);
this.listLevelsShowing.get(i).setImageAlign(Align.CENTER);
this.listLevelsHoveredImage.get(i).setImageAlign(Align.CENTER);
this.listLevelsShowing.get(i).setVisible(true);
}
}
[/code]`
I've checked everything with prints. Even ~~*~~Spritesheets.get()* and ~~*~~Spritesheet.getSprite()*. And everything's correct.
So my last conclusion is: their could be, sometimes, that a pointer points towards two different sub-images. And I was wondering if
[b]~~*~~parallelStream()*[/b] would be responsible, or something somewhere in[b]~~*~~Resources.load()*[/b]...?Beta Was this translation helpful? Give feedback.
All reactions