SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › помогите пж, все перепроверил, не понимаю в чем проблема!!
Помечено: камера
В этой теме 2 ответа, 2 участника, последнее обновление spoty76 7 года/лет, 1 месяц назад.
-
АвторСообщения
-
Вообщем писал 2дшку, я уже сделал карту, все работало, но когда я сделал камеру, визуалка не компилирует, (visual studio 2013, sfml 2.4.2). Пишет такую ошибку:
1>—— Сборка начата: проект: Adventures, Конфигурация: Debug Win32 ——
1> main.cpp
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(9): error C2086: float Player::x: переопределение
1> c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(7): см. объявление “Player::x”
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(9): error C2086: float Player::y: переопределение
1> c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(7): см. объявление “Player::y”
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(22): warning C4244: =: преобразование “int” в “float”, возможна потеря данных
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(23): warning C4244: аргумент: преобразование “float” в “int”, возможна потеря данных
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(72): warning C4244: инициализация: преобразование “sf::Int64″ в “float”, возможна потеря данных
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(84): warning C4305: =: усечение из “double” к “float”
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(85): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(92): warning C4305: =: усечение из “double” к “float”
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(93): warning C4244: +=: преобразование “double” в “float”, возможна потеря данных
1>c:\users\spoty\documents\visual studio 2013\projects\adventures\adventures\main.cpp(114): warning C4244: аргумент: преобразование “int” в “float”, возможна потеря данных
========== Сборка: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========Перепроверил код и с сайта и с видео, все перепроверил, у меня ничего красным не выделяет визуалка, но вот такая ошибка, вот код:
main.cpp:
#include <SFML/Graphics.hpp>
#include “map.h”
#include “view1.h”
using namespace sf;class Player {
private: float x, y;
public:
float x, y, w, h, dx, dy, speed = 0;
int dir = 0;
String File;
Image image;
Texture texture;
Sprite sprite;
Player(String F, int X, int Y, float W, float H) {
File = F;
w = W; h = H;
image.loadFromFile(“images/” + File);
image.createMaskFromColor(Color(41, 33, 59));
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);
}float getplayercoordinateX()
{
return x;
}
float getplayercoordinateY()
{
return y;
}
};int main()
{
sf::RenderWindow window(sf::VideoMode(1270, 800), “Glinskii Adventures”);
view.reset(sf::FloatRect(0, 0, 640, 480));Image map_image;
map_image.loadFromFile(“images/map.png”);
Texture map;
map.loadFromImage(map_image);
Sprite map_sprite;
map_sprite.setTexture(map);Player p(“hero.png”, 250, 675, 94.0, 96.0);
float CurrentFrame = 0;
Clock clock;
while (window.isOpen())
{
float time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time / 800;sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}if (Keyboard::isKeyPressed(Keyboard::D)) {
p.dir = 0; p.speed = 0.1;
CurrentFrame += 0.005*time;
if (CurrentFrame > 3) CurrentFrame -= 3;
p.sprite.setTextureRect(IntRect(97 * int(CurrentFrame), 192, 94, 96));
getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());
}if (Keyboard::isKeyPressed(Keyboard::A)) {
p.dir = 1; p.speed = 0.1;
CurrentFrame += 0.005*time;
if (CurrentFrame > 3) CurrentFrame -= 3;
p.sprite.setTextureRect(IntRect(96 * int(CurrentFrame), 96, 94, 96));
getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());
}p.update(time);
window.setView(view);
window.clear();
for (int i = 0; i < HEIGHT_MAP; i++)
for (int j = 0; j < WIDTH_MAP; j++)
{
if (TileMap[i][j] == ‘3’) map_sprite.setTextureRect(IntRect(96, 0, 32, 32));
if (TileMap[i][j] == ‘0’) map_sprite.setTextureRect(IntRect(128, 0, 32, 32));
if (TileMap[i][j] == ‘2’) map_sprite.setTextureRect(IntRect(160, 0, 32, 32));
if (TileMap[i][j] == ‘ ‘) map_sprite.setTextureRect(IntRect(192, 0, 32, 32));
if ((TileMap[i][j] == ‘1’)) map_sprite.setTextureRect(IntRect(224, 0, 32, 32));map_sprite.setPosition(j * 32, i * 32);
window.draw(map_sprite);
}
window.draw(p.sprite);
window.display();
}return 0;
}view.h (у меня сейчас называется view1.h, я это учел и поменял в main.cpp include, но даже с view.h ничего не работало)
#include <SFML\Graphics.hpp>
using namespace sf;
sf::View view;void getplayercoordinateforview(float x, float y)
{
view.setCenter(x + 100, y);
}До разработки камеры все работало стабильно вместе с картой, не понимаю в чем проблема, помогите
C++12345//в классе Player:private:float x, y;public:float x, y, ....Одинаковые переменные. Компилятор не может решить, каким из них присваивать значения.
Спасибо, просто когда мы переходили на ооп, мы прсали эти коррдинаты, а в видео не говорилось что их надо поменять
-
АвторСообщения
Для ответа в этой теме необходимо авторизоваться.