Создал класс Player, далее его параметр, после этого создал процедуру обновления координат игрока, компилирую - выдает вот такую ошибку:
Error 35 error C2039: 'update' : is not a member of 'Player' c:\users\livolickie\documents\visual studio 2012\projects\sfml\sfml\main.cpp 103 1 SFML
Сам код:
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace sf;
class Player
{
public:
float x,y,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)
{
dx = 0;
dy = 0;
speed = 0;
dir = 0;
File = F;
w = W;
h = H;
image.loadFromFile("textures/"+File);
image.createMaskFromColor(Color(41,33,59));
texture.loadFromImage(image);
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()
{
Player p("hero.png",250,250,96.0,96.0);
RenderWindow window(sf::VideoMode(640, 480), "Test");
Clock clock;
float c_frame;
c_frame = 0;
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::W))
{
p.dir = 3; p.speed = 0.1;
c_frame += 0.005*time;
if (c_frame >3) c_frame = 0;
p.sprite.setTextureRect(IntRect(96*int(c_frame),288,96,96));
}
if (Keyboard::isKeyPressed(Keyboard::A))
{
p.dir = 1; p.speed = 0.1;
c_frame += 0.005*time;
if (c_frame >3) c_frame = 0;
p.sprite.setTextureRect(IntRect(96*int(c_frame),96,96,96));
}
if (Keyboard::isKeyPressed(Keyboard::S))
{
p.dir = 2; p.speed = 0.1;
c_frame += 0.005*time;
if (c_frame >3) c_frame = 0;
p.sprite.setTextureRect(IntRect(96*int(c_frame),0,96,96));
}
if (Keyboard::isKeyPressed(Keyboard::D))
{
p.dir = 0; p.speed = 0.1;
c_frame += 0.005*time;
if (c_frame >3) c_frame = 0;
p.sprite.setTextureRect(IntRect(96*int(c_frame),192,96,96));
}
p.update(time);
window.clear();
window.draw(p.sprite);
window.display();
}
return 0;
}