我有一个类AwesomeMousePointer
,它具有一些开始在鼠标上播放动画的功能:
class AwesomeMousePointer{
void startAnimat();
void stopAnimat();
};
我有另一个对象,我负责确定鼠标动画是否应该启动(这是基于对对象的内部命中测试,例如:如果鼠标在对象内的特定时间)
class SomeShape(){
Event<MouseArgs> startAnim
Event<bool> interrutptAnim
bool hitTest(int x, int y);
//Inside some loop function, check if the mouse is inside the object
if(hitTest(mouseXPos, mouseYPos)){
//if the mouse if inside for x time
NotiftyEvent(startAnim, MouseArgs);
}
else{
//mouse left the object
NotifyEvent(interruptAnim, false);
}
现在,再次在我的内部AwesomeMousePointer
,我将为事件添加侦听器,即
AddListener(SomeShape::startAnim, &AwesomeMousePointer::startAnim);
AddListener(SomeShape::interruptAnim, &AweseommousePointer::interruptAnim);
在我尝试过的简短不同示例中,使用单事件系统NotifyEvent
并且AddListener
工作正常。现在在我的这个应用程序中,我有很多对象SomeShape
和一个AwesomeMousePointer
. 我的问题是,动画的上述逻辑是否有效,或者我是否应该明确传递SomeShape
对象以订阅他们的事件,在这种情况下事情会变得有点困难。
例如:
AddListener(shapeObject1.startAnim, &AwesomeMousePointer::startAnimat);
AddListener(shapeObject2.startAnim, &AwesomeMousePointer::startAnimat);
AddListener(shapeObject3.startAnim, &AwesomeMousePointer::startAnimat);
或者
AddListener(SomeShape::startAnim, &AwesomeMousePointer::startAnimat);
上面的第二个会成功吗?如果不是,那么在不明确传递对象的情况下如何完成,因为这会导致不清楚并且ShapeObjects
不应该在MousePointer
.
如果我将内部的事件SomeShape
设为静态,这会起作用吗?
static Event<MouseArgs> startAnim
static Event<bool> interrutptAnim