witam.
Mam taki oto kod:
main.cpp
#include <SFML/Graphics.hpp>
#include "tile.hpp"
int main() {
// create the window
sf::RenderWindow window(sf::VideoMode::getFullscreenModes()[0], "My window", sf::Style::Fullscreen);
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
{
window.close();
}
}
// clear the window with black color
window.clear(sf::Color(150, 220, 255));
// draw everything here...
// window.draw(...);
sf::View ppp;
//iew.zoom(0.5f);
ppp.setRotation(5.f);
window.setView(ppp);
Tile aaa;
aaa.set(10, 10);
window.draw(aaa);
// end the current frame
window.display();
}
return 0;
}
tile.cpp
//----------------------------------------------------------------------
#include <SFML/Graphics.hpp>
#include "tile.hpp"
//----------------------------------------------------------------------
void Tile::set(float x, float y) {
sf::Texture texture;
texture.loadFromFile("textures/ppp.png");
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition( x, y);
}
tile.hpp
#ifndef TILE_HPP
#define TILE_HPP
#include <SFML/Graphics.hpp>
class Tile {
private:
public:
float x;
float y;
void set(float x, float y);
};
#endif
przy kompilacji wywala mi:
joszi@joszi-MS-7309:~/sfml$ make lin
rm -f *.o
rm -f app
g++ -I ./include/ -c *.cpp
main.cpp: In function ‘int main()’:
main.cpp:50:16: error: no matching function for call to ‘sf::RenderWindow::draw(Tile&)’
window.draw(aaa);
^
In file included from ./include/SFML/Graphics.hpp:45:0,
from main.cpp:1:
./include/SFML/Graphics/RenderTarget.hpp:237:10: note: candidate: void sf::RenderTarget::draw(const sf::Drawable&, const sf::RenderStates&)
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
^~~~
./include/SFML/Graphics/RenderTarget.hpp:237:10: note: no known conversion for argument 1 from ‘Tile’ to ‘const sf::Drawable&’
./include/SFML/Graphics/RenderTarget.hpp:248:10: note: candidate: void sf::RenderTarget::draw(const sf::Vertex*, std::size_t, sf::PrimitiveType, const sf::RenderStates&)
void draw(const Vertex* vertices, std::size_t vertexCount,
^~~~
./include/SFML/Graphics/RenderTarget.hpp:248:10: note: candidate expects 4 arguments, 1 provided
./include/SFML/Graphics/RenderTarget.hpp:258:10: note: candidate: void sf::RenderTarget::draw(const sf::VertexBuffer&, const sf::RenderStates&)
void draw(const VertexBuffer& vertexBuffer, const RenderStates& states = RenderStates::Default);
^~~~
./include/SFML/Graphics/RenderTarget.hpp:258:10: note: no known conversion for argument 1 from ‘Tile’ to ‘const sf::VertexBuffer&’
./include/SFML/Graphics/RenderTarget.hpp:269:10: note: candidate: void sf::RenderTarget::draw(const sf::VertexBuffer&, std::size_t, std::size_t, const sf::RenderStates&)
void draw(const VertexBuffer& vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates& states = RenderStates::Default);
^~~~
./include/SFML/Graphics/RenderTarget.hpp:269:10: note: candidate expects 4 arguments, 1 provided
Makefile:14: recipe for target 'lin' failed
make: *** [lin] Error 1
joszi@joszi-MS-7309:~/sfml$
kompiluję z makefile:
plik Makefile:
CC_LIN = g++
INC_LIN = -I ./include/
LIB_LIN = -L ./lib/ -lsfml-graphics -lsfml-window -lsfml-system
CLEAN_OBJ = rm -f *.o
CLEAN_APP = rm -f app
clean:
$(CLEAN_OBJ)
$(CLEAN_APP)
lin:
$(CLEAN_OBJ)
$(CLEAN_APP)
$(CC_LIN) $(INC_LIN) -c *.cpp
g++ *.o $(LIB_LIN) -o app
$(CLEAN_OBJ)
co robię źle ?
chciałbym stworzyć sprite jako obiekt i wyświetlić go na ekranie.