Clicking on a button generates an object. I can click the button again and it will generate another. If I drag one of the objects to a bin icon it deletes that instance that collided with it (collision = delete object event). However, all the other objects on the screen then lose their dragable behaviour. What could be going wrong here?
I don’t know what is the problem on your side, but it doesn’t seem to be a problem here.
delete_dragableobject.zip (6.26 KB)
Thank you for the example copy. I had all the same parts but I just had “object collides with bin THEN delete” as opposed to “when left mouse button is released, (sub) object collides with bin THEN delete”.
Go figure what the logic does, as you can still collide the object without releasing the button but it now works hahaa . Thank you :*
It is checking collision between the green objects and the bin only if the mouse button is released.
If you drag a green object on to the bin, it is not checking collision until you release the left mouse button.
When you release the left mouse button, the collision between the green objects and the bin is going to be checked only a single time for a period of a single frame because the mouse is considered to be “released” only for the period of one frame, after that it is considered “not pressed”.
The logic I used here is to attempt deleting the objects only if the left mouse button is released which is indicates you may have just dragged and dropped something and check collision only a single time to see if you have dropped something on to the bin. It helps with performance.
You can improve it further if you also check if the mouse is over the bin before checking collision, because that way you don’t waist performance on collision checking since if the mouse is over the bin then it is more likely you have just dropped something on to the bin, if the mouse is not over the bin at the moment of releasing the mouse button then it is unlikely you have dropped something on to the bin and the collision checking is not necessary.
Left mouse button was released
-sub: The cursor/touch is on bin
--sub: object is in collision with bin THEN delete the object
But of course, this way you may causing a little bug, as depends on the size of the object you want to delete, the object may well overlapping the bin but the mouse isn’t over the bin then the collision checking is not happening and the object is not going to be deleted even though it is colliding wit the bin… It very easy to cause bugs even when you try to be logical
Ahhh okay I get it. Because it is being held by the mouse. Thanks
Final version uploaded to my website. A bit buggy but working at least!
Looks nice. Regarding bugs I have noticed only 3.
When you drag an object sometime it is below the other letters on the board. To avoid that, just simply change the Z order of the one that being dragged. Set the Z-order of the board to be 1, the letters on the board 2 and anything is dragged set the Z order to be 3.
When something is dropped (no longer dragged), just change the Z order back to 2.
We can change the upper and lowercase letters and the board even if we hold down the mouse button while move it over the buttons. You can fix this one too by simply trigger the action when mouse is released instead of pressed unless you have a good reason to use mouse pressed instead.
Finally, in case you want to let the kids to add a letter to the board only if the box in the bottom left corner is empty, you can just check if any letter is in collision with that area before add the selected letter.
Okay great. Thank you for the feedback