RMMV Images load correctly on first load, second load they are gone

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
123
Reaction score
50
First Language
English
Primarily Uses
RMMV
Hey guys,

I have a costum scene where I load planets for the solar system.
Every planet has 2 images. One for when the planet is not selected and one for selected.

The first time when the scene is loaded, everything loads correctly and all planet images are visible.
When I exit the scene and re-enter, they never appear again. No matter how many times I reload, until I quit the game.

This is what I know so far when they don't show:

- The planet sprites exist and have all the parameters as if there was an image (e.g. width, height, opacity, x, y)

- The image address remains the same and is shown correctly

- When I manually add a planet sprite through the console (e.g. "earth.png") it still won't show. But when I copy it and make a "earth2.png" it will show. Which tells me that planet png's once loaded, won't load anymore for whatever reason.
I can add any other non-planet image manually through the console in the game.

- It's not stuck on a loop that would prevent the images from showing

- It all started when I added the on-selection-images. Before that this problem never occured.

- Reserving the planet images works for the first time the scene is loaded, but not on re-entering the scene.

- The image cache has been expanded to hold 100 x 1000 x1000 pixels. The limit is not the issue I tested for 500 x 1000 x1000

- The Object structure is SceneManager._scene._planets[x]._selected and ._planets[x]._unselected. The planets are added as a child to the scene of course.

- The layering doesn't change and remains correct when scene is loaded and re-loaded.

My guess is that it has something to do with the cache failing to clear or for whatever reason is overloading.
Like I said, it all started when I added the extra on-selection-images. However, if that's the case I don't understand why it would load correctly on the first run and then fail on re-entering the scene.

Thankful for any ideas!
 

Attachments

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,446
First Language
English
Primarily Uses
N/A
This could be a lot of things, it's hard to say without seeing how you're loading, and what you're doing to unload the images.
It sounds like you're using the image manager, since you said reserve.

So are you not creating these as PIXI.Sprite objects?
Also, what happens when you reload the scene and then manually add the missing image to SceneManager._scene again? Even if you can confirm it's already there.

PIXI.Sprites can have multiple references, but can only belong to one Container, so that's another thing to look out for.

But anyway, I could help with more info
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
123
Reaction score
50
First Language
English
Primarily Uses
RMMV
This could be a lot of things, it's hard to say without seeing how you're loading, and what you're doing to unload the images.
It sounds like you're using the image manager, since you said reserve.

So are you not creating these as PIXI.Sprite objects?
Also, what happens when you reload the scene and then manually add the missing image to SceneManager._scene again? Even if you can confirm it's already there.

PIXI.Sprites can have multiple references, but can only belong to one Container, so that's another thing to look out for.

But anyway, I could help with more info
Thanks for your response.

I never messed around with PIXI sprites, only used the ImageManager thus far. Are PIXI sprites easier to use?

Also, what happens when you reload the scene and then manually add the missing image to SceneManager._scene again? Even if you can confirm it's already there.
I tried this before and for some strange reason nothing happens. However, when I rename the "earth.png" to "earth2.png" and then try again, it works. So for whatever reason the ImageManager doesn't want to an already loaded png - or - the ImageManager thinks since it's the same png, it will just use the loaded image in the cache?

I preload the planet png's in the Scene_Boot class. Otherwise they wouldn't show at all.
I tried reserving the images in the Scene_TacMap.prototype.initializing method, which is the scene for the galaxy, but that didn't help either.

JavaScript:
Scene_Boot.prototype.reserveAllPlanets = function() {
    var planets = [
        "earth",
        "mercury",
        "jupiter",
        "venus",
        "mars",
        "saturn",
        "uranus",
        "neptune",
        "pluto"
    ];
    for (i = 0; i < planets.length; i++) {
        ImageManager.reserveTacMapImage(planets[i]);
        ImageManager.reserveTacMapImage("targeted_p_" + planets[i]);
    }
};
This is the loading method. It's a bit messy, sorry.

JavaScript:
Scene_TacMap.prototype.loadPlanet = function(filename, satelliteArray, faction, name, x, y, x2, y2) {
    var planetName = String(filename);
    var planet = name;
    var textX = x2 || 0;
    var textY = y2 || 0;
    var planet = new Sprite();
    var selected = new Sprite();
    var unselected = new Sprite();
    if (planetName !== "station" && planetName !== "vessel") {
        selected.bitmap = ImageManager.loadTacMapImage("targeted_p_" + planetName);
    } else {
        selected.bitmap = new Bitmap();
    }
    unselected.bitmap = ImageManager.loadTacMapImage(planetName);
    planet._selected = selected;
    planet._unselected = unselected;
    planet.x = x;
    planet.y = y;
    planet._satelliteArray = satelliteArray === "" ? [] : satelliteArray;
    planet._faction = faction;
    planet._class = planetName;
    planet._id = name.toLowerCase();
    planet._name = new Sprite();
    planet._name.bitmap = new Bitmap(100,50);
    planet._name.bitmap.fontSize = this._labelSize;
    planet._name.x = textX - planet._unselected.bitmap.measureTextWidth(planetName.toUpperCase());
    planet._name.y = textY;
    planet.addChild(planet._unselected);
    planet.addChild(planet._selected);
    planet.addChild(planet._name);
    planet._isSelected = false;
    planet._isUnveiled = true;
    this._planets.push(planet);
    this.addChild(planet);   
};
And this is the code for checking on cursor colision with the planets, to change the planet appearance and text to selected. This is being checked every frame in the Scene_TacMap.prototype.update method:

JavaScript:
Scene_TacMap.prototype.checkCollision = function() {
    var cur = this._cursor;
    var cw = cur.width * this._cursorScaleX;
    var ch = cur.height * this._cursorScaleY;
    var cx = cur.x + cw/6*3;
    var cy = cur.y + ch/6*3;
    var cx2 = cx + cw/6;
    var cy2 = cy + ch/6;
    for (i = 0; i < this._planets.length; i++) {
        var plnt = this._planets[i];
        var pw = plnt._unselected.width;
        var ph = plnt._unselected.height;
        var px = plnt.x;
        var py = plnt.y;
        var px2 = px + pw;
        var py2 = py + ph;
        if (cx >= px && cx <= px2 || cx < px && cx2 > px2) {
            if (cy >= py && cy <= py2 || cy2 >= py && cy2 <= py2 || cy < py && cy2 > py2) {
                this.drawPlanetSelect(plnt);
                if (!this.isUnveiled(plnt)) this.unveil(plnt);
                this.select(plnt);
            } else {
                this.drawPlanet(plnt);
                this.unselect(plnt);
            }
        } else if (cx2 >= px && cx2 <= px2 || cx < px && cx2 > px2) {
            if (cy >= py && cy <= py2 || cy2 >= py && cy2 <= py2 || cy < py && cy2 > py2) {
                this.drawPlanetSelect(plnt);
                if (!this.isUnveiled(plnt)) this.unveil(plnt);
                this.select(plnt);
            } else {
                this.drawPlanet(plnt);
                this.unselect(plnt);
            }
        } else {
            this.drawPlanet(plnt);
            this.unselect(plnt);
        }
    }
};

Scene_TacMap.prototype.drawPlanetSelect = function(planet) {
    planet._name.bitmap.clear();
    if (!this.isPlanet(planet)) {
        planet._name.bitmap.textColor = planet.textColor(0);
        planet._name.bitmap.drawText(planet._faction.toUpperCase(), 0, 0, 100, this._lineHeight, "right");
        planet._name.bitmap.drawText(planet._id.toUpperCase(), 0, this._lineHeight, 100, this._lineHeight, "right");
    } else {
        planet._unselected.bitmap.clear();
        planet._selected.bitmap.clear();
        planet._unselected.opacity = 0;
        planet._selected.opacity = 255;
        planet._name.bitmap.textColor = planet.textColor(0);
        planet._name.bitmap.drawText(planet._id.toUpperCase(), 0, 0, 100, 20, "right");
    }
};

Scene_TacMap.prototype.drawPlanet = function(planet) {
    planet._name.bitmap.clear();
    if (!this.isPlanet(planet)) {
        planet._name.bitmap.textColor = planet.textColor(9);
        planet._name.bitmap.drawText(planet._faction.toUpperCase(), 0, 0, 100, this._lineHeight, "right");
        planet._name.bitmap.drawText(planet._id.toUpperCase(), 0, this._lineHeight, 100, this._lineHeight, "right");
    } else {
        planet._unselected.bitmap.clear();
        planet._selected.bitmap.clear();
        planet._unselected.opacity = 255;
        planet._selected.opacity = 0;
        planet._name.bitmap.textColor = planet.textColor(1);
        planet._name.bitmap.drawText(planet._id.toUpperCase(), 0, 0, 100, 20, "right");
    }
};
Again, sorry for the mess, I'm in the middle of coding this, so it's not refined code.

Thanks for your help!
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,446
First Language
English
Primarily Uses
N/A
Honestly, yeah if you're trying to do code related stuff that interacts with images, it is easier imo to use PIXI.Sprites. It's not hard to clean them up when you're done if you just follow a few simple rules.

My answers won't be able to satisfy this thread's title, because I actually don't ever use the ImageManager. There's nothing wrong with it, but like I said before, it's not built to serve you in coding, it's more built to interact with the base code to handle things like loading the projects png's for icons, Show Picture, etc.

The advantage is it will clean up after itself fairly well, and it Reserves images, basically meaning it won't let you perform things on the resulting Sprite if it hasn't loading yet. With PIXI Sprites, you have to handle this on your own, which isn't hard.

If you don't find a solution or just wanna know how to use PIXI.Sprites, pm me. I could either teach you, point you to resources to learn or just send you a version my image cache or something.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
123
Reaction score
50
First Language
English
Primarily Uses
RMMV
Honestly, yeah if you're trying to do code related stuff that interacts with images, it is easier imo to use PIXI.Sprites. It's not hard to clean them up when you're done if you just follow a few simple rules.

My answers won't be able to satisfy this thread's title, because I actually don't ever use the ImageManager. There's nothing wrong with it, but like I said before, it's not built to serve you in coding, it's more built to interact with the base code to handle things like loading the projects png's for icons, Show Picture, etc.

The advantage is it will clean up after itself fairly well, and it Reserves images, basically meaning it won't let you perform things on the resulting Sprite if it hasn't loading yet. With PIXI Sprites, you have to handle this on your own, which isn't hard.

If you don't find a solution or just wanna know how to use PIXI.Sprites, pm me. I could either teach you, point you to resources to learn or just send you a version my image cache or something.
Thanks, will do! The ImageManager is, quite frankly, a pain in the lower area of my bottox. I've been having nothing but trouble with the cache, preloading, reserving images. There is always something wrong.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Yesterday I made my first step towards eating more healthily.
I saw candy on discount and did not buy it.
"They yearn for what they fear for."
I always told my DA fans how much I hate slot machines. They're fine in games as a risk-and-reward system. But when you're spending REAL MONEY in a Vegas casino to try and hit the jackpot (which very, very few people will), it can really hurt your budget. Gambling is a bad habit, and I don't like wasting my money on a slim chance. Go to Vegas for the experience, not the jackpot.
Took the kids to a corn maze. They gave us a map and had lights at certain points in the maze. Not overwhelming... or underwhelming... just... whelming.
Okay, vacuuming fruit flies out of the air is surprisingly effective.

Forum statistics

Threads
104,393
Messages
1,006,073
Members
135,927
Latest member
ecelebrithytrend
Top