Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I can't create another sprite  (Read 2142 times)

0 Members and 1 Guest are viewing this topic.

NoobsDeSroobs

  • Newbie
  • *
  • Posts: 8
    • View Profile
I can't create another sprite
« 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;
}

TricksterGuy

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
I can't create another sprite
« Reply #1 on: June 20, 2010, 08:47:39 am »
You shouldn't name variables the same name as the class

i.e. these lines

Code: [Select]

Image Image;


Code: [Select]

Sprite Sprite(Image);


After those lines if you try to declare an Image you will get errors as you see that you have now.

you could use its full name sf::Image then it will work.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
I can't create another sprite
« Reply #2 on: June 20, 2010, 01:10:51 pm »
Don't use "using namespace" directive, will be easier.

Anyway, you load two times a file into "Image" (and never into "Image2").

PS : use [ code ] [ / codeĀ ] blocks.
SFML / OS X developer

NoobsDeSroobs

  • Newbie
  • *
  • Posts: 8
    • View Profile
I can't create another sprite
« Reply #3 on: June 20, 2010, 10:09:18 pm »
Thank you, I can see it now. Thank you so much. I have been sitting for 3 days now.

 

anything