我正在使用SFML进行c ++游戏.我已经写了一个用于移动玩家的代码,但是当游戏启动玩家时,移动但是当我离开按钮时玩家返回其原始位置.可以帮助我吗?
主要的:
#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(1320, 840), "Window");
window.setPosition(sf::Vector2i(150, 50));
window.setSize(sf::Vector2u(1320, 840));
window.getPosition();
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(5);
window.getSize();
while (window.isOpen()) {
window.clear(sf::Color::White);
//texture
sf::Texture texture;
if (!texture.loadFromFile("/users/gaetanodonnarumma/desktop/background1.png", sf::IntRect(0, 0, 1320, 840))) {
return -1;
}
sf::Texture playerTexture;
if (!playerTexture.loadFromFile("/users/gaetanodonnarumma/desktop/quadrato-giallo.jpg", sf::IntRect(0, 0, 70, 70))) {
return -1;
}
//sprite
sf::Sprite backgroud;
backgroud.setTexture(texture);
sf::Sprite player;
double pX = 0;
double pY = 770;
player.setTexture(playerTexture);
player.setPosition(sf::Vector2f(pX, pY));
player.getPosition();
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close(); …Run Code Online (Sandbox Code Playgroud) 我正在使用C ++中的SDL2和OpenGL开发一个简单的应用程序。
问题是我的程序没有绘制三角形。
Rect.hpp(绘制三角形的类):
#ifndef Rect_hpp
#define Rect_hpp
#include <stdio.h>
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include "Shaders.hpp"
using namespace std;
extern GLfloat vertices[];
class Rect
{
public:
Rect();
~Rect();
void init();
void draw();
private:
void bind();
GLuint VAO;
GLuint VBO;
GLuint vertexShader;
GLuint fragmentShader;
GLuint shaderProgram;
Shaders shaders;
};
#endif /* Rect_hpp */
Run Code Online (Sandbox Code Playgroud)
Rect.cpp:
#include "Rect.hpp"
GLfloat vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
};
Rect::Rect()
{
VBO = NULL;
vertexShader = …Run Code Online (Sandbox Code Playgroud)