Okay, I had to change it a bit for it to work cause it wouldn't do anything otherwise:
var rectName = self(this)["id"]
window["rectName"] = new Sprite(bitmap)
But now it only works on mouse click for some reason (I don't have any mouse click conditions)
And weirdly the eraser tool still only removes one rectangle
😀
I'm lost
Here's my new code:
Code:
◆Si:Script:s["paint mode"] == 1
◆Script:self(this)["id count"] = 0
◆Etiqueta:erase
◆Script:self(this)["id count"] += 1
◆Script:var rectName = self(this)["id count"]
: :window["rectName"].bitmap.clearRect(self(this)["xMath"], self(this)["yMath"], self(this)["pixel size"], self(this)["pixel size"])
◆Si:Script:self(this)["id count"] != self(this)["id"]
◆Ir a etiqueta:erase
◆
:Fin
◆
:Otro
◆Script:self(this)["id"] += 1
◆Script:var bitmap = new Bitmap(816, 624);
: :bitmap.fillRect(self(this)["xMath"], self(this)["yMath"], self(this)["pixel size"], self(this)["pixel size"], "rgb(255, 0, 0)")
: :var rectName = self(this)["id"]
: :window["rectName"] = new Sprite(bitmap)
: :SceneManager._scene.addChild(window["rectName"]);
◆
:Fin
Maybe I could create an Undo button instead. Is it possible to use clearRect without bitmaps parameters? To simply remove it by it's id.
I don't know what you are doing with the "self" thing as I said before.
What does
self(this)["id"] returns?
You need to know that the
window keyword is an object( global object ), and what you are doing is creating new properties for that object.
To create a new property on an object, in javascript, you can do one of that below:
JavaScript:
object.propertyName
object["string"]
object[variable]
In the case of a variable, it must return a
string or a
number value.
I suggest you first create your rectangles outside the logic of your event. Which means, without the "self" thing. Just like I did before.
Create 3 rectangles and play with them. Change its place, draw, clear, etc. Once you are done with it, you can try to apply that to your event logic.
Another suggestion would be for you to create an array instead, to add all your rectangles(it's a little bit more advanced than what we are doing before):
window.myRectList = []
And then add all your rectangles there:
JavaScript:
// Create the rectangle
var bitmap = new Bitmap(400, 400)
bitmap.fillRect(0, 0, 400, 400, "red")
var sprite = new Sprite(bitmap)
// Add to Scene Map
SceneManager._scene.addChild(sprite)
// Add to your rectangle list
window.myRectList.push(sprite)
So to reference your rectangles, you can use:
window.myRectList[index] // Replace index with a number starting from zero. This will return the sprite that holds your rectangle(bitmap)
0 = first rectangle
1 = second rectangle
etc...
window.myRectList[0].bitmap.clearRect(x, y, width, height)