Joined
May 21, 2021
Messages
3
Reaction score
1
First Language
Swedish
Primarily Uses
RMMV
I have an event that creates a new sprite container from image files in the pictures folder, using PIXI.js.
I love this!!!! As long as z value is negative, it draws under the tile map!! Sweet!!
I copied it from an older post here and thought it would be useful for my game. (Thanks to Shaz for pointing out tilemap property in SceneManager).

It works in every way I desire it to by adjusting some parameters...except now I cannot get rid of the pictures created by this method.
I have tried removeChild();
I have tried sprite.destroy();
I have tried rmmv script calls to clear pictures.
var image = PIXI.Sprite.fromImage('./img/pictures/mybackground.png'); SceneManager._scene._spriteset._tilemap.addChild(image); img.x = 0; img.y = 0; img.z = -8; img.width = 816; img.height = 624;

Any further attempts to get rid of it throws me an error:
Type Error: Undefined is not a function
Reference Error: image is not defined.

How do I remove these images...and if the same method of drawing is repeated several times, will it consume all of my device's memory?
Thanks in advance! :)

Screenshot info: It is a fan game of MTG (Magic: the gathering). Many of the land cards in MTG contain panoramic images of cool looking fantasy places. I can reposition and enlarge the card images so that only the portion showing the landscape art is visible, creating a faux parallax layer. In this screenshot, the image is enlarged only slightly, and drawn below the tilemap.
 

Attachments

  • Untitled.png
    Untitled.png
    278.6 KB · Views: 5

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
4,518
Reaction score
1,737
First Language
Dutch
Primarily Uses
RMMV
I used to play MTG and will play when times comes.

But "Type Error of undefined is not a function" can be anything:

1) wrong plugin order
2) continue from save file after new plugin is added
3) plugin conflict
4) typo in scriptcall/plugin command

but to narrow down the the error, we need to check the console log
to see which one throws the error to find out what function it has.

if it's a conflict, it can be easier to know which one, in order to find that out,
turn off all plugin (if they are in the correct order) and turn them on 1 by 1
to see which one is conflicting it.
 
Joined
May 21, 2021
Messages
3
Reaction score
1
First Language
Swedish
Primarily Uses
RMMV
Oh wow that's a lot of red! I just attempted to run removeChild() in vanilla mode and this is what it gave me.

ReferenceError: img is not defined
at Game_Interpreter.eval (eval at <anonymous> (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:10482:10), <anonymous>:1:53)
at Game_Interpreter.command355 (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:10482:5)
at Game_Interpreter.executeCommand (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:8932:34)
at Game_Interpreter.update (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:8840:19)
at Game_Map.updateInterpreter (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:6117:27)
at Game_Map.update (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_objects.js:6024:14)
at Scene_Map.updateMain (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_scenes.js:420:14)
at Scene_Map.updateMainMultiply (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_scenes.js:412:10)
at Scene_Map.update (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_scenes.js:401:10)
at Function.SceneManager.updateScene (file:///C:/Users/jeremy/Documents/Games/Project1/js/rpg_managers.js:1829:25)rpg_managers.js:1756 SceneManager.catchExceptionrpg_managers.js:1717 SceneManager.update
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,860
Reaction score
2,196
First Language
EN
Primarily Uses
RMMZ
var image = PIXI.Sprite.fromImage('./img/pictures/mybackground.png'); SceneManager._scene._spriteset._tilemap.addChild(image); img.x = 0; img.y = 0; img.z = -8; img.width = 816; img.height = 624;
I see a few problems here:
  1. You declare var image, but then attempt to manipulate img, a different (possibly undefined) reference.

  2. Script commands are sandboxed evals: all local variables are destroyed once the code is evaluated. To avoid this, you will need to store the reference as a (sub-)property of a pre-existing object, e.g. window (root global) or SceneManager._scene (active scene).

  3. By using PIXI.Sprite directly you ignore the game's image caching system (keeps recently-loaded images in RAM for quick access) and maybe other things.
You may want to try something like this (untested):
  • Define a new, globally-accessible array for your background images:
    JavaScript:
    window.myBG = [];  // initialise empty array
  • Load new pictures via RMMV's Sprite and ImageManager wrappers:
    JavaScript:
    window.myBG.push(new Sprite(ImageManager.loadPicture('mybackground')));
  • Add/adjust the child image as usual.
  • Reference the array when removing images:
    JavaScript:
    SceneManager._scene._spriteset._tilemap.removeChild(window.myBG.splice(0, 1));
    I.e. "splice image 0 (first image) out of the array and remove that image from the tilemap".
push just adds a new entry to an array, and splice lets you add/remove entries. More info here:
Note that this sort of thing will only persist for a single session, so it may have problems with images showing when they're not supposed to or vice-versa, e.g. on new/load game. This looks like a feature that would generally be best done with a plugin using appropriate method hooks. :kaoslp:

Also, be aware of copyright! You should have permission to use these images legally. This applies regardless of whether you intend to profit from your project.
 

Latest Threads

Latest Posts

Latest Profile Posts

actor name string, why you gotta be case sensitive like that?
Doing RPG Maker News for 26th October 2021

My entire world, full of monsters and treasures, will likely be done by the end of the year. After that it's all NPCs and side quests... then done. I'm never making an open world game again xD
The more I read Calvin and Hobbes as an adult, the more I deeply respect Bill Watterson. Plenty of stuff flew over my head, but now that I'm old enough to appreciate the viewpoints he shared with the fun and imagination? I am grateful that C&H was basically my early childhood.
After years of relying on others and the community to help with making my games, I've decided to delve into the world of scripting. Thought I'd share a few simple scripts that I made that I'm very proud of and excited about!

Forum statistics

Threads
116,101
Messages
1,095,781
Members
151,490
Latest member
Davidlcf
Top