1 decade ago by empika
Hallo
Another plugin from me! ...well, two. One injects into the entity class and one into the game class.
The entity_utilities contains the isMouseInside function to check if the mouse is withing the entity aswell as the actual dragAndDrop function. Just pop the dragAndDrop function into your entities update function.
dragAndDrop takes a few arguments:
snap - bool: snap to the grid. No need to use snap_after_drop with this, just set that to false.
snap_after_drop - bool: snap to the grid when the mouse is let go
snap_grid_size_x - int: the grid size to snap to, defaults to the entities width
snap_grid_size_y - int: the grid size to snap to, defaults to the entities width
The game_utilities contains a function called entitiesUnderMouse which returns all the entities that are under the mouse when called. This means we can drag and drop only the entity under the mouse with the highest zindex.
Code is up on github: https://github.com/empika/ImpactJS-Plugins
And working demo files can be found here: https://github.com/empika/ImpactJS-Demo-Code
I will also keep the live demo (although compressed) so you can see how this stuff should be behaving here: http://labs.nixmc.com/~eddy/game/
Cheers and enjoy!
Another plugin from me! ...well, two. One injects into the entity class and one into the game class.
The entity_utilities contains the isMouseInside function to check if the mouse is withing the entity aswell as the actual dragAndDrop function. Just pop the dragAndDrop function into your entities update function.
dragAndDrop takes a few arguments:
snap - bool: snap to the grid. No need to use snap_after_drop with this, just set that to false.
snap_after_drop - bool: snap to the grid when the mouse is let go
snap_grid_size_x - int: the grid size to snap to, defaults to the entities width
snap_grid_size_y - int: the grid size to snap to, defaults to the entities width
The game_utilities contains a function called entitiesUnderMouse which returns all the entities that are under the mouse when called. This means we can drag and drop only the entity under the mouse with the highest zindex.
Code is up on github: https://github.com/empika/ImpactJS-Plugins
And working demo files can be found here: https://github.com/empika/ImpactJS-Demo-Code
I will also keep the live demo (although compressed) so you can see how this stuff should be behaving here: http://labs.nixmc.com/~eddy/game/
Cheers and enjoy!