我被卡住了,太烦人了...我有发送鼠标坐标的 Windows 消息,并且我有一个可以看到这些坐标的游戏循环,但是当我调用一个查看鼠标坐标的类时,它看不到鼠标坐标,它只是创建自己的鼠标版本,而不管我定义 global.h 并在使用它的 .cpp 文件上引用 extern :
鼠标.h
#pragma once
class Mouse
{
public:
int x;
int y;
void MouseMove( int x, int y );
Mouse();
};
全球.h
#include "Mouse.h"
static Mouse mouse;
Game.cpp //代码片段//
Game::Game( HWND hWnd, Mouse &mouse )
:
gfx( hWnd ),
mouse( mouse )
{
...
if( scenes[ a ]->interactiveObjects[ b ]->CheckCollision( mouse.x, mouse.y ) )
{
.... // Game is looping if no messages stored, the windows loop updates my mouse coordinates by calling a routine in my Mouse.cpp. My windows loop sends the mouse through as a parameter to my game object which I no longer want to use... I want to use my global mouse as the mouse reference.
“InteractiveObject.cpp”它包含“Global.h”并引用其中声明的鼠标......对吗?那么为什么我的检查碰撞没有看到mouse.x和mouse.y(我必须从我的游戏对象中传递坐标作为参数mouseX和mouseY :(
#include "Global.h"
extern Mouse mouse;
#include "InteractiveObject.h"
InteractiveObject::InteractiveObject( int id_, string title_, Image* theImage_, int type_, int x_, int y_, int z_ )
:
id( id_ ),
title( title_ ),
theImage( theImage_ ),
type( type_ ),
x( x_ ),
y( y_ ),
z( z_ )
{
pos.x = x_;
pos.y = y_;
pos.z = z_;
}
bool InteractiveObject::CheckCollision( int mouseX, int mouseY )
{
if(
mouse.x > x &&
mouse.x < x + theImage->width &&
mouse.y > y &&
mouse.y < y + theImage->height
)
/*if(
mouseX > x &&
mouseX < x + theImage->width &&
mouseY > y &&
mouseY < y + theImage->height
)*/
{
return TRUE;
}
return FALSE;
}