ImageTransparencyCalculator - Check sprite on click

#1

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
    %D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5
  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)

Link: https://github.com/JAlHund/ImageTransparencyCalculator
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

9 Likes

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

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
check_click.init({
    game_object_id1,
    game_object_id2,
    ...
})
  1. Check click
    if check_click.check(game_object_id, x, y) then
        print("Clicked")
    else
        print("No :(")
    end

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

How it works in the example:
%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9%20%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82

3 Likes

#3

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

2 Likes

#4

Really cool project! Thank you for sharing!

1 Like