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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Scipi

Pages: 1 [2]
16
Window / problem with view movement
« on: November 01, 2011, 04:55:43 pm »
Noted, thanks.

I ended up using View.SetCenter on the characters coords plus halve the size of the sprite to get the center and it works perfectly. I did not know about the sf::Clock. What algorithm could I use to get what sprite should be displayed for each part of the animation?

The format I use now switches between three sprites in a vector and switches between them in the order of 0, 1, 0, 2 to get the animation.

17
Window / problem with view movement
« on: October 22, 2011, 08:48:43 pm »
Hello,

I am making an RPG using SFML and I'm running into this problem when it comes to views. I have this code:

Code: [Select]

/////////////
//ANIMATE
/////////////
 
void Character::Animate(sf::RenderWindow& App, Game& Game)
{
    float offset =  128 * App.GetFrameTime();
    if(PosX < MapX * 64)
        {
            PosX += offset;
            Game.View.Move(offset, 0);
        }
    else if(PosX > MapX * 64)
        {
            PosX -= offset;
            Game.View.Move(-offset, 0);
        }
    else if(PosY < MapY * 64)
        {
            PosY += offset;
            Game.View.Move(0, offset);
        }
    else if(PosY > MapY * 64)
        {
            PosY -= offset;
            Game.View.Move(0, -offset);
        }
    else if(PosX == MapX * 64 && PosY == MapY * 64)
        {
            Moving = false;
            //PosX ++;
            //MapX++;
            //PosY++;
            //MapY++;
            //cout << "Moving == false";
        }
    Timer++;
    if(Timer == 1 && Moving)
        Direction++;
    else if(Timer == 8 && Moving)
        Direction--;
    else if(Timer == 16 && Moving)
        Direction += 2;
    else if (Timer == 24 && Moving)
        Direction -= 2;
    if(Moving)
     cout << Timer << " ";
    //else if (Timer == 64)
    //cout << PosX << " " << PosY << " " << MapX << " " << MapY << "\n";
 
 
    return;
}


Which is called once a arrow key is pressed. However, the view is moving faster than the character though they ought to be moving at the same speed. Any ideas as to what's going wrong? Thanks! :D

18
Graphics / Problem using Images and Sprites from within a class
« on: July 26, 2011, 06:08:11 pm »
Disregard, I found out what was wrong.

It was when I was resizing the sf::Image and sf::Sprite vectors and it was breaking the pointers.

19
Graphics / Problem using Images and Sprites from within a class
« on: July 26, 2011, 06:54:12 am »
Hello, I am trying to display sprites inside a class function to display to the screen. However I am getting nothing but a wall of white. Here's my code:

Code: [Select]

class Game
{
public:

        sf::RenderWindow App;
        sf::View View;
        vector <sf::Sprite> SpriteFiles;
        vector <int> MapData;
        vector <int> CollisionData;
        vector <int> TransitionData;
vector <sf::Image> ImageFiles;
void Setup();
        void LoadMap(string);//Map to load ID
void Display();

        //void Setup();
        void MainMenu();
        void GetEvents();

        void LevelUp(string, int*);//Daemon name, pointer to Daemon stats array

//Game();
//~Game();
private:
bool FilesExist;


int MapWidth, MapHeight, ScreenWidth, ScreenHeight, PosX, PosY;
};


^ The class sf::Sprite and sf::Image are initialized in

Code: [Select]

void Game::Setup()
{
App.Create(sf::VideoMode(1024, 768), "Daemons");

App.UseVerticalSync(true);//Clearer graphics ftw

//sf::View View(sf::FloatRect(0,0,1024,768));
    View.SetFromRect(sf::FloatRect(0,0,1024,768));
App.SetView(View);//Sets up the view. So you can see stuff
App.SetFramerateLimit(60);

FilesExist = true;
int ImageNum = 0;
ScreenWidth = 17;
ScreenHeight = 13;
PosX = -1;
PosY = -1;
stringstream PictureName;

for(ImageNum = 0; ImageNum < 10; ImageNum++)
    {

        PictureName << "data/images/map/" << ImageNum << ".png";

ImageFiles.resize(ImageNum + 1);
SpriteFiles.resize(ImageNum + 1);


        if(ImageFiles[ImageNum].LoadFromFile(PictureName.str().c_str()))
        {
            ImageFiles[ImageNum].SetSmooth(false);
            SpriteFiles[ImageNum].SetImage(ImageFiles[ImageNum]);
        }
cout << "\n" << PictureName.str().c_str() << "\n";
PictureName.str(string());
       

    }

return;
}



////////////////////
//DISPLAY
////////////////////
void Game::Display()
{
try
{
        App.Clear();
        for (int y=PosY; y<ScreenHeight; y++)
            {
                for (int x=PosX; x<ScreenWidth; x++)
                {
                    if ((y >= 0 && x >= 0) && (y <= ScreenHeight && x <= ScreenWidth))
                    {
                        if (MapData[x + (y * MapWidth)] == -1)
                            continue;
                        int holder = MapData[x + (y * MapWidth)];
                        SpriteFiles[holder].SetPosition(x * 64, y * 64);

                        //cout << holder;
                        App.Draw(SpriteFiles[holder]);
                    }
                }

            }
        App.Display();
}
catch(exception& e)
{
   cout << e.what() << "\n";
}
return;
}


^Where they are used

So what exactly is causing the images to not display correctly and how can I fix it?

Thanks.

Pages: 1 [2]
anything