SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Ошибка 'File' was not declared in the scope
В этой теме 1 ответ, 1 участник, последнее обновление ratatyq 8 года/лет, 5 мес. назад.
Просмотр 2 сообщений - с 1 по 2 (из 2 всего)
-
АвторСообщения
-
При компиляции выдает ошибку “‘File’ was not declared in the scope”
Вот код:C++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106#include <SFML/Graphics.hpp>#include <iostream>using namespace sf;class Player{public:float x, y, w, h, dx, dy, speed = 0; // Его данные при создания персонажа.int dir = 0; // направление игрокаString file;Image image;Texture texture;Sprite sprite;Player(String F, float X, float Y, float W, float H) // Отвечает за конструктор класса тоесть что вписывать когда мы создаем объект{File = F;w = W;h = H;image.loadFromFile("image/" + File);sprite.setTexture(texture);x = X;y = Y;sprite.setTextureRect(IntRect(0,0,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);}};int main(){RenderWindow form1(VideoMode(1024,768), "Game1");Player p("players.png", 170, 0, 83, 72);/* Texture playerTexture;playerTexture.loadFromFile("image/players.png");Sprite playerSprite;playerSprite.setTexture(playerTexture);playerSprite.setTextureRect(IntRect(170,0,83,72));playerSprite.setPosition(60, 60); */Clock clocks;// float Animation = 0;while (form1.isOpen()){float time = clocks.getElapsedTime().asMicroseconds();clocks.restart();time = time/800;sf::Event event;while (form1.pollEvent(event)){if (event.type == sf::Event::Closed)form1.close();}/*if (Keyboard::isKeyPressed(Keyboard::D)){Animation += 0.005*time;if (Animation > 5)Animation -= 5;playerSprite.setTextureRect(IntRect(87*int(Animation),0,83,74));playerSprite.move(0.1*time, 0);}if (Keyboard::isKeyPressed(Keyboard::A)){Animation += 0.005*time;if (Animation > 5)Animation -= 5;playerSprite.setTextureRect(IntRect(87*int(Animation),100,80,74));playerSprite.move(-0.1*time, 0);}if (Keyboard::isKeyPressed(Keyboard::W)){Animation += 0.005*time;if (Animation > 5) Animation -= 5;playerSprite.setTextureRect(IntRect(87*int(Animation),200,70,74));playerSprite.move(0,-0.1*time);}if (Keyboard::isKeyPressed(Keyboard::S)){Animation += 0.005*time;if (Animation > 5) Animation -= 5;playerSprite.setTextureRect(IntRect(87*int(Animation),310,70,74));playerSprite.move(0,0.1*time);} */form1.clear();form1.draw(p.sprite);form1.display();}return 0;}Вот картинка отладки:
Вложения:
You must be logged in to view attached files.Решил проблему, не правильно указала название переменной File там где назначал ее было с маленькой буквы а я писал с большой.
-
АвторСообщения
Просмотр 2 сообщений - с 1 по 2 (из 2 всего)
Для ответа в этой теме необходимо авторизоваться.