8
« on: June 20, 2010, 08:07:38 am »
I am just learning SFML at the moment, but so far it has been logical. This problem does not brake any logical reasoning and thus I can't seem to find the cause for it all.
I created the first sprite, made it move and stuff. Then I wanted to create a bullet or ranged attack for it, so I made the image and created the sprite JUST like the tutorial said. Still I get the unidentified identifier error.
Here is the code:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace std;
using namespace sf;
int main()
{
RenderWindow App(VideoMode(800, 600, 32), "DICKFACED");
App.SetFramerateLimit(60);
Image Image;
Image.LoadFromFile("Animal.tga");
Image.CreateMaskFromColor(Color(255,0,255),0);
Image Image2;
Image.LoadFromFile("FIRE.tga");
Image.CreateMaskFromColor(Color(255,0,255),0);
Sprite Sprite(Image);
Sprite.SetX(154.f);
Sprite.SetY(114.f);
Sprite.SetCenter(10.f, 10.f);
Sprite Fire(Image2);
bool up = false;
bool down = false;
bool left = false;
bool right = false;
bool shoot = false;
while (App.IsOpened())
{
Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == Event::Closed)
App.Close();
Sprite.GetPosition();
if ((Event.Type == Event::KeyReleased) && (Event.Key.Code == Key::Escape))
{
App.Close();
}
if (Event.Type == Event::KeyPressed)
{
switch (Event.Key.Code)
{
case Key::Up:
up = true;
break;
case Key::Down:
down = true;
break;
case Key::Left:
left = true;
break;
case Key::Right:
right = true;
break;
case Key::Space:
shoot = true;
default:
break;
}
}
if (Event.Type == Event::KeyReleased)
{
switch (Event.Key.Code)
{
case Key::Up:
up = false;
break;
case Key::Down:
down = false;
break;
case Key::Left:
left = false;
break;
case Key::Right:
right = false;
break;
default:
break;
}
}
}
if(up)
{
Sprite.Move(cos(Sprite.GetRotation()*3.14159265/180), sin(Sprite.GetRotation()*3.14159265/180)*-1);
}
if(down)
{
Sprite.Move(cos(Sprite.GetRotation()*3.14159265/180)*-1, sin(Sprite.GetRotation()*3.14159265/180));
}
if(left)
{
Sprite.Rotate(3);
}
if(right)
{
Sprite.Rotate(-3);
}
if(shoot)
{
Fire.SetPosition(Sprite.GetPosition);
Fire.Move(cos(Fire.GetRotation()*3.14159265/180), sin(Fire.GetRotation()*3.14159265/180)*-1);
}
App.Clear(Color(255,255,255));
//Draw stuff
App.Draw(Sprite);
App.Display();
}
return 0;
}