ImageTransparencyCalculator - Check sprite on click


I wrote two projects, one of which uses native extensions. The first generates a special file with data of image transparency. The second uses it to determine if the sprite is clicked or not.

Now you can determine whether the game object clicks, even if it is of complex shape without physics!

How to use

  1. Open ImageTransparencyCalculator project
  2. Put images in a folder Images and write their size in image_data.lua%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5
  3. Run the project and click anywhere. It will close automatically, and files will appear in the folder generated_data
  4. Copy generated files to folder generated data in project Check Click
  5. Position the game object with the sprite in the game. Plug in module check_click.lua
  6. Specify game object identifiers to load their data
  7. You can check clicked game object or not using check_click.check(game_object_id, x, y)
  8. Specify a folder generated_data in custom resources

Perfect accuracy is often not needed, you can customize it and reduce the file size here:
(ImageTransparencyCalculator project)

License: MIT
Written for Defold 1.2.169

The texture of London from my game. We all perfectly understand that not all of London is like that, and this is just the name of the province


How to detect click on a game object? (SOLVED)
Get pixel from the render target

To determine the click in your game you need:

  1. Generate files in ImageTransparencyCalculator project and add in your project
  2. Add and require check_click.lua
  3. Init data using
  1. Check click
    if check_click.check(game_object_id, x, y) then
        print("No :(")

Project Check click is example of how to work and track clicks
Project ImageTransparencyCalculator generates files for this

How it works in the example:



Bundling error fixed (I forgot about custom resources)
Added zlib, now the generated files weigh even less:
Compression: 2, image from example
Size: 23,6 kb -> 799b



Really cool project! Thank you for sharing!

1 Like