SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Выдаёт ошибку при компиляции
Помечено: sfml
В этой теме 5 ответов, 2 участника, последнее обновление Павел Букреев 8 года/лет, 8 мес. назад.
-
АвторСообщения
-
Выдаёт ошибку при компиляции, не могу понять, где находится эта ошибка. ПОМОГИТЕ!
Сорри за файлы
Вложения:
You must be logged in to view attached files.Вряд ли кто захочет качать просто так.
Напиши что за ошибка и выложи код с помощью кнопки вставки кода прям в тему текстомC++12345678910111213141516171819202122232425262728293031323334353637383940414243#include <SFML\Graphics.hpp>using namespace sf;class Player{private: float x, y;public: float x, y, w, h, dx, dy, speed;int dir;String File;Image image;Texture texture;Sprite sprite;Player(String F, int X, int Y, float W, float H){y = 0;speed = 0;dir = 0;File = F;w = W; h = H;image.loadFromFile("Images/" + File);texture.loadFromImage(image);sprite.setTexture(texture);x = X; y = Y;sprite.setTextureRect(IntRect(w, h, w, h));}void update(float time){switch (dir){case 0: dx = speed; dy = 0; break;case 1: dx = -speed; dy = 0; break;case 2: dx = 0; dy = speed; break;case 3: dx = 0; dy = -speed; break;}x += dx*time;y += dy*time;speed = 0;sprite.setPosition(x, y);}};C++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include <SFML/Graphics.hpp>#include "Player.cpp"using namespace sf;int main(){RenderWindow window(VideoMode(1280, 720), "GAMESFML I");Player p("player.png", 0, 0, 32, 32);float CurrentFrame = 0;Clock clock;while (window.isOpen()){float time = clock.getElapsedTime().asMicroseconds();clock.restart();time = time/800;Event event;while (window.pollEvent(event)){if (event.type == Event::Closed)window.close();}/*----УПРАВЛЕНИЕ---*/if ((Keyboard::isKeyPressed(Keyboard::Left) || (Keyboard::isKeyPressed(Keyboard::A)))) {p.dir = 1; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(32 * int(CurrentFrame), 32, 32, 32));}if ((Keyboard::isKeyPressed(Keyboard::Right) || (Keyboard::isKeyPressed(Keyboard::D)))) {p.dir = 0; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(32 * int(CurrentFrame), 0, 32, 32));}if ((Keyboard::isKeyPressed(Keyboard::Up) || (Keyboard::isKeyPressed(Keyboard::W)))) {p.dir = 3; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(32 * int(CurrentFrame), 64, 32, 32));}if ((Keyboard::isKeyPressed(Keyboard::Down) || (Keyboard::isKeyPressed(Keyboard::S)))) {p.dir = 2; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(64 * int(CurrentFrame), 32, -32, 32));}p.update(time);window.clear();window.draw(p.sprite);window.display();}return 0;}1>—— Построение начато: проект: GameSFML I, Конфигурация: Debug Win32 ——
1>Построение начато 06.11.2015 22:43:48.
1>InitializeBuildStatus:
1> Обращение к “Debug\GameSFML I.unsuccessfulbuild”.
1>ClCompile:
1> player.cpp
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(7): error C2086: float Player::x: переопределение
1> c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(6): см. объявление “Player::x”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(7): error C2086: float Player::y: переопределение
1> c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(6): см. объявление “Player::y”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(24): warning C4244: =: преобразование “int” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(24): warning C4244: =: преобразование “int” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1> main.cpp
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(7): error C2086: float Player::x: переопределение
1> c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(6): см. объявление “Player::x”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(7): error C2086: float Player::y: переопределение
1> c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(6): см. объявление “Player::y”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(24): warning C4244: =: преобразование “int” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(24): warning C4244: =: преобразование “int” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\player.cpp(25): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(17): warning C4244: инициализация: преобразование “sf::Int64″ в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(30): warning C4305: =: усечение из “double” к “float”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(31): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(37): warning C4305: =: усечение из “double” к “float”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(38): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(44): warning C4305: =: усечение из “double” к “float”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(45): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(52): warning C4305: =: усечение из “double” к “float”
1>c:\users\adim\desktop\projects\gamesfml i\gamesfml i\main.cpp(53): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1> Создание кода…
1>
1>СБОЙ построения.
1>
1>Затраченное время: 00:00:01.76
========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========посмотри на сообщения об ошибке и ищи там слова error .
написано, что переопределение х на 7 строке, так и есть – ты сначала объявил private х, затем public. поэтому не компилируется -
АвторСообщения
Для ответа в этой теме необходимо авторизоваться.