简体   繁体   English

如何处理对象的鼠标悬停[Allegro5 / C ++]

[英]How to handle mouse hovering for object [Allegro5/C++]

I want to be able to register/de-register Objects to a list and check if the mouse is hovering over them to display tool-tips. 我希望能够将对象注册/注销到列表中,并检查鼠标是否将鼠标悬停在它们上方以显示工具提示。 However I'm stumbling at the beginning. 但是我一开始就绊脚石。

I'm going to use: al_get_pixel & al_unmap_rgba to retrieve the alpha of each pixel and decide if it's visible enough to count as a hit when hovering over it with the mouse. 我将使用: al_get_pixelal_unmap_rgba检索每个像素的alpha值,并确定当鼠标悬停在其上方时,它是否足够可见以算作命中点。

The major problem I'm having is working out how best to store this individual "hitmap" & the reference to the object that generated it; 我遇到的主要问题是研究如何最好地存储此单个“ hitmap”以及对生成它的对象的引用。 As many different types objects (as struct's) of different sizes may need hitmaps generated. 由于可能需要生成大小不同的许多不同类型的对象(如struct的对象)。 I was hoping I could do something similar to checking if the complex object 'extends' the base object but I don't see how I can achieve this in c++. 我希望我能做些类似于检查复杂对象是否“扩展”基础对象的事情,但是我不知道如何用c ++实现。

Ps; PS; I know I could create an array the size of the screen for each object, but I'm doing this mainly with the purpose of maximizing efficiency. 我知道我可以为每个对象创建一个屏幕大小的数组,但是我这样做主要是为了最大程度地提高效率。 I'd make dynamic sized arrays but... 我会制作动态大小的数组,但是...

al_get_pixel will work, but it will be terribly slow, even if you lock all your bitmaps, unless you use something like a picking buffer. al_get_pixel可以工作,但是,即使您锁定了所有位图,它的速度也会非常慢,除非您使用诸如拾取缓冲区之类的东西。 The basic idea is to render every interactive area on each object with a different color id. 基本思想是用不同的颜色ID渲染每个对象上的每个交互区域。 This means you need to draw your scene twice, once normally, and once with picking colors. 这意味着您需要绘制两次场景,正常情况下绘制一次,并用颜色进行绘制一次。 Then when you need to read back a mouse position, you can use the picking buffer to read a single pixel and get its color id. 然后,当您需要回读鼠标位置时,可以使用拾取缓冲区读取单个像素并获取其颜色ID。

You might also want to try different methods of collision detection, such as bounding boxes, bounding circles, or other easily collision detectable shapes. 您可能还想尝试不同的碰撞检测方法,例如边界框,边界圆或其他易于碰撞检测的形状。

There is a third option, which is pixel perfect collision. 第三种选择是像素完美碰撞。 It involves making 1bpp masks out of all your objects and then checking for collision between those. 它涉及在所有对象中制作1bpp蒙版,然后检查这些对象之间是否存在碰撞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM