MV Optimized way to Remove\Clear a bitmap

Hope I'm not spamming. I made a grid-based cursor of sorts, but if I'm moving it my FPS slowly drops:

Code:
//deleting the old cursor bitmap
window.myCursorList[0].bitmap.clearRect(self(this)["xMathCursor"], self(this)["yMathCursor"], self(this)["pixel size"], self(this)["pixel size"])
window.myCursorList.splice(0)
window.myCursorList[0].bitmap.clear()

//drawing a new one
var bitmap = new Bitmap(816, 624);
bitmap.fillRect(self(this)["xMath"], self(this)["yMath"], self(this)["pixel size"], self(this)["pixel size"], self(this)["color"])
var cursor = new Sprite(bitmap);
SceneManager._scene.addChildAt(cursor, 3)
window.myCursorList.push(cursor)

//save coordinates of the old one  to delete it later
self(this)["xMathCursor"] = self(this)["xMath"]
self(this)["yMathCursor"] = self(this)["yMath"]

Rectangles do get deleted and it all works fine visually. FPS is the only problem.
The whole thing is in a loop and It won't draw rectangles with the same coordinates over and over again.
self(this)[X] is a variable
Did you put this in a loop event?

My guess is that you keep drawing a new one.
Make sure that part only happens once.
Hi!

You need to divide that into 3 different processes.
One thing is to draw a bitmap. Another is to add it to the scene.

// clear/delete the old "draw"
// Don't need to call clear rect if already call the .clear()
window.myCursorList[0].bitmap.clear()

// drawing a new one
//If the bitmap already exists on the map, just draw it again, without adding it to the map:
window.myCursorList[INDEX].bitmap.clear() // Clear previous draws
window.myCursorList[INDEX].bitmap.fillRect(...arguments) // Draw again

// Add to map: This only need to be done once.
var bitmap = new Bitmap(816, 624);
bitmap.fillRect(self(this)["xMath"], self(this)["yMath"], self(this)["pixel size"], self(this)["pixel size"], self(this)["color"])
var cursor = new Sprite(bitmap);
SceneManager._scene.addChildAt(cursor, 3)
window.myCursorList.push(cursor)

I believe the best way to help is to know what you are trying to do, specifically.
@Eliaquim Hi
It works 😀
My thinking was that window.myCursorList[0].bitmap.clear() would delete my bitmap.
Wierd. How do I delete a bitmap then?
Does this mean that my erased bitmaps stay around and keep affecting my FPS?
@Eliaquim Hi
It works 😀
My thinking was that window.myCursorList[0].bitmap.clear() would delete my bitmap.
Wierd. How do I delete a bitmap then?
Does this mean that my erased bitmaps stay around and keep affecting my FPS?
You don't need to delete the bitmaps. You just need to clear them.

A bitmap is like a piece of paper. You draw over it. You erase it with the eraser.
But the paper remains there.

window.myCursorList[0].bitmap.clear() // This is what the eraser do.

To remove it from the Map child, you have to destroy the sprite that holds the bitmap:
window.myCursorList[0].destroy()

But I don't think you need to do that. It's kinda hard without know what you are doing.
I suggest you take a look at some tutorials. I believe Poryg has a lot of them on youtube.
😳
I thought you need to use removeChild before destroy...?
So it's automatically removed if you destroy the sprite?
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/optimized-way-to-remove-clear-a-bitmap.139866/