SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Не выводится персонаж.
В этой теме 7 ответов, 3 участника, последнее обновление Alexey 8 года/лет, 6 мес. назад.
Просмотр 8 сообщений - с 1 по 8 (из 8 всего)
-
АвторСообщения
-
Проблема заключается в том, что после настройки границ карты перестал выводится персонаж. Очень нужна помощь. Код ниже:
C++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175#include "header.h"using namespace sf;class Player {private:float x, y;public:float w, h, dx, dy, speed;int dir ;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;x = X; y = Y;image.loadFromFile("images/"+File);texture.loadFromImage(image);sprite.setTexture(texture);sprite.setTextureRect(IntRect(0, 0, w, h));}void update(float time){switch (dir){default: dx=0, dy=0;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);InteractionWithMap();}void InteractionWithMap(){for(int i=y/32; i<(y + h)/32; i++){for(int j=x/32; j<(x + w)/32; j++){if(TileMap[i][j] == '0'){if(dy>0){y=i*32-h;}if(dy<0){y=i*32+32;}if(dx>0){x=j*32-w;}if(dx<0){x=j*32+32;}}}}}float getplayercoordinateX(){return x;}float getplayercoordinateY(){return y;}};int main(){RenderWindow window(sf::VideoMode(800, 600), "Test game");Music music;music.openFromFile("sound/Jacob_Plant_-_Drop_That.ogg");music.play();Texture Backscrn;Backscrn.loadFromFile("images/Space1.png");Sprite background(Backscrn);float CurrentFrame = 0;Clock clock;Image map_image;map_image.loadFromFile("images/map.png");Texture map;map.loadFromImage(map_image);Sprite s_map;s_map.setTexture(map);Player player("rocket.png",250,250,65.0,65.0);while (window.isOpen()){float time = clock.getElapsedTime().asMicroseconds();clock.restart();time = time / 400;sf::Event event;while (window.pollEvent(event)){if (event.type == sf::Event::Closed)window.close();if ((Keyboard::isKeyPressed(Keyboard::Escape)))window.close();}//-----------------CONTROLL-------------------\\if ((Keyboard::isKeyPressed(Keyboard::Left) || (Keyboard::isKeyPressed(Keyboard::A)))) {player.dir = 1; player.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;}if ((Keyboard::isKeyPressed(Keyboard::Right) || (Keyboard::isKeyPressed(Keyboard::D)))) {player.dir = 0; player.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;}if ((Keyboard::isKeyPressed(Keyboard::Up) || (Keyboard::isKeyPressed(Keyboard::W)))) {player.dir = 3; player.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;}if ((Keyboard::isKeyPressed(Keyboard::Down) || (Keyboard::isKeyPressed(Keyboard::S)))) {player.dir = 2; player.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;}player.update(time);window.clear();//-------------------MAP-----------------------\\for (int i = 0; i < HEIGHT_MAP; i++)for (int j = 0; j < WIDTH_MAP; j++){if (TileMap[i][j] == ' ') s_map.setTextureRect(IntRect(0, 0, 32, 32));if ((TileMap[i][j] == '0')) s_map.setTextureRect(IntRect(64, 0, 32, 32));s_map.setPosition(j * 32, i * 32);window.draw(s_map);}//window.draw(background);window.draw(player.sprite);window.display();}return 0;}Заранее благодарю!
координаты появления персонажа пробовал сделать чуть правее и ниже?
Пробовал, но нет. Было такое предположение что оно где-то сзади, но и это не так.
Выведи в консоль координаты персонажа.
У тебя не инициализированы переменные dx, dy, speed в классе Player.
Все получилось, спасибо господа!
-
АвторСообщения
Просмотр 8 сообщений - с 1 по 8 (из 8 всего)
Для ответа в этой теме необходимо авторизоваться.