stworzyłem dwie klasy i chce ustawić shape z klasy zombie danymi z zombie odziedziczoną metodą update z klasy player. Gdy odpalam to program działa ale nie wyświetla shape zombie.
#include <SFML/Graphics.hpp>
#include "Player.h"
#include "Zombie.h"
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(1920, 1080), "SFML works!");//sf::Style::Fullscreen
window.setFramerateLimit(60);
Player p1;
Zombie z1;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
p1.update();
z1.update();
window.draw(p1.shape);
window.draw(z1.shape);
window.display();
}
return 0;
}
#ifndef ZOMBIE_H
#define ZOMBIE_H
#include "Player.h"
class Zombie : public Player
{
public:
Zombie();
sf::CircleShape shape;
int x=500;
int y=500;
int r=100;
protected:
private:
};
#endif // ZOMBIE_H
#ifndef PLAYER_H
#define PLAYER_H
#include "SFML/Graphics.hpp"
#include <iostream>
class Player
{
public:
sf::CircleShape shape;
Player();
int x=100;
int y=100;
int r=40;
void update();
protected:
private:
};
#endif // PLAYER_H
#include "Player.h"
Player::Player()
{
shape.setOrigin(r,r);
}
void Player::update()
{
shape.setPosition(x,y);
shape.setRadius(r);
shape.setFillColor(sf::Color::Blue);
}