Giter Site home page Giter Site logo

Add Mouse Support about tilengine HOT 4 CLOSED

popeyeotaku avatar popeyeotaku commented on September 1, 2024
Add Mouse Support

from tilengine.

Comments (4)

megamarc avatar megamarc commented on September 1, 2024

Hi @everyfan, assisted mouse support was introduced in release 1.21, exposing the underlying SDL2 events to tilengine with the SDL_SetSDLCallback function. This API function is briefly documented but easy to use, and there's a fully working example in the main repository: https://github.com/megamarc/Tilengine/blob/master/samples/TestMouse.c.
You'll need the SDL2 development headers because the example interfaces directly with the SDL2 library.

from tilengine.

 avatar commented on September 1, 2024

Hi Marc.

I have a problem with this, it has to do with the window factor.
In TestMouse.c

#define WIDTH 400  // I only take the width to simplify

Next, Window.c

wnd_width = wnd_params.width*factor;

wnd_width = 400 * 3;  then wnd_width equal to 1200

The SDL_Mouse coordinates correspond to the window(w=1200), not the sprite(x= 180 y=166)
The solution is simple, get the factor and then divide that factor to the mouse coordinate:

If Window.c

 factor = 3

Then TestMouse.c

if (entity->enabled &&
 mouse->x / factor >= entity->x && mouse->y / factor  >= entity->y &&

Is it possible to change the API, to return the factor, or better, to transform a coordinate according to the factor?

from tilengine.

popeyeotaku avatar popeyeotaku commented on September 1, 2024

from tilengine.

megamarc avatar megamarc commented on September 1, 2024

@daltomi: of course that's a bug! Thanks for pointing it. I'll fix it. Mouse input should return the coordinates in framebuffer space, not in window space. Window scaling factor shouldn't affect the returned value.
@everyfan: the SDL2 bridge to handle events is implemented into the main library, but not into the python binding.

from tilengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.