后来测试了一下
不是无法调用函数的问题
下面上代码
Player.h
----------
#pragma once
#include "BasicInclude.h"
namespace Player {
static float Player_x;
static float Player_y;
static float Player_z;
void Move();
}
----------
Player.cpp
----------
#include "Player.h"
using namespace Player;
void Player::Move() {
if (glfwGetKey(MainWindow, GLFW_KEY_W)) { Player::Player_z += 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_S)) { Player::Player_z -= 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_A)) { Player::Player_x += 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_D)) { Player::Player_x -= 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_SPACE)) { Player::Player_y += 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_LEFT_SHIFT)) { Player::Player_y -= 0.01; }
else if (glfwGetKey(MainWindow, GLFW_KEY_RIGHT_SHIFT)) { Player::Player_y -= 0.01; }
}
----------
MineCubeWorld.cpp
----------
int main() {
glfwInit();
MainWindow = glfwCreateWindow(WinWidth, WinHeight, WinTitle.c_str(), NULL, NULL);
glfwMakeContextCurrent(MainWindow);
do {
Player::Move();
printf("X: %f Y: %f Z: %f \n", Player::Player_x, Player::Player_y, Player::Player_z);
glfwPollEvents();
if (glfwGetKey(MainWindow, GLFW_KEY_ESCAPE)) { exit(EXIT_SUCCESS); }
} while (!glfwWindowShouldClose(MainWindow));
glfwTerminate();
return 0;
}
问题描述:
如果把Player::Move()函数的代码放在主循环里 就可以调用与执行
但是 如果在主循环里调用Player::Move()函数的话 Move()函数可以被调用与执行 但是不能给Player::Player_x Player::Player_y Player::Player_z 赋值
这三个数据都是float的
守候你守候我
相关分类