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 - LucasShadow

Pages: 1 [2] 3 4
16
Graphics / [SFML 2.0] How to render tiles to texture?
« on: May 19, 2012, 01:31:31 am »
So I am trying to create a simple terrain for my game right now and know through reading many different posts and articles that having a single sprite for each tile is the wrong way to go about it.  I know I need to have a single sprite, which I set the image for, position, and then draw to a texture which is then drawn every game loop.  But how do you actually do that third step? Drawing the tile to the texture? I am still getting used to SFML 2.0, so if you could point me to the correct documentation I would be very appreciative.

17
Graphics / Too many sprites?
« on: March 28, 2012, 02:30:27 am »
So I am working on creating a very large tile-based map. Obviously, this requires quite a few sprites. Some of the code below:

int WorldXS = 100;
int WorldYS = 105;
sf::Sprite Tile[WorldXS * WorldYS];
 

Of course, I set positions and images for all of the tiles, and then draw them all. However, if I increase WorldXS or WorldYS by one more, it compiles, but the .exe stops working. This leads me to believe that SFML has a hard sprite limit of 10,500 sprites (WorldXS * WorldYS) ?

18
Graphics / Overlapping Array not working?
« on: March 06, 2012, 05:41:04 am »
I am not sure where I have gone wrong, but this program is supposed to first randomly position a bunch of rocks, and then check to see if each one is overlapping any of the others. The randomly distributing I got working, but the checking for overlappings is proving difficult.

Full Code:
Code: [Select]
#include <SFML/Graphics.hpp>

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "SRock Test");

     ///Set the number of rocks, load picture, set sprite, etc
     int NumberOfRock1 = 500;
     sf::Image Rock1Img;
     if(!Rock1Img.LoadFromFile("rock1.png")) {}
     Rock1Img.SetSmooth(false);
     sf::Sprite Rock1[NumberOfRock1];

     for (int i = 1; i < NumberOfRock1; i++) Rock1[i].SetImage(Rock1Img);///Set rock images
     for (int i = 1; i < NumberOfRock1; i++) Rock1[i].SetPosition(sf::Randomizer::Random(0, 800), sf::Randomizer::Random(0,600)); ///Randomly allocate the rocks

     for (int i = 1; i < NumberOfRock1; i++) ///Now lets check for overlapping of all the rocks
     {
         ///Get the position and dimension of a rock
         float XPCurrent = Rock1[i].GetPosition().x;
         float YPCurrent = Rock1[i].GetPosition().y;

         ///Check against all the previous rocks in the sequence
         for (int j = 0; j < (i - 1); j++)
         {
             float XPPrevious = Rock1[j].GetPosition().x;
             float YPPrevious = Rock1[j].GetPosition().y;
             float XSPrevious = Rock1[j].GetSize().x;
             float YSPrevious = Rock1[j].GetSize().y;

             ///Check to see if they are overlapping
             if( (XPCurrent>=XPPrevious) && (XPCurrent<=(XPPrevious+XSPrevious)) && (YPCurrent>=YPPrevious) && (YPCurrent <= (YPPrevious + YSPrevious)) )
             {
                 Rock1[i].SetPosition(-100, -100); ///Remove the rock if it is overlapping another
             }
         }
         ///Now check against all the rocks afterwards in the sequence
         for (int k = (i + 1); k < NumberOfRock1; k++)
         {
             float XPAfter = Rock1[k].GetPosition().x;
             float YPAfter = Rock1[k].GetPosition().y;
             float XSAfter = Rock1[k].GetSize().x;
             float YSAfter = Rock1[k].GetSize().y;

             ///Check to see if they are overlapping
             if( (XPCurrent>=XPAfter) && (XPCurrent<=(XPAfter+XSAfter)) && (YPCurrent>=YPAfter) && (YPCurrent <= (YPAfter + YSAfter)) )
             {
                 Rock1[i].SetPosition(-100, -100); //Remove the rock if it is overlapping another
             }
         }
     }

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         App.Clear();

         for(int i = 0; i < NumberOfRock1; i++) App.Draw(Rock1[i]);

         App.Display();
     }
     return EXIT_SUCCESS;
 }


Picture of current generation: http://puu.sh/jDCR
As you can see, they overlap one another...any suggestions much appreciated.
[/url]

19
General / SFML Compiling
« on: February 11, 2012, 11:12:53 pm »
Well, I would prefer a link to a pre-compiled version...but here is the problem(s):

I was following the tutorial provided and when I selected the appropriate generator for CodeBlocks MinGW Makefiles.  I then hit "Configure and received the following errors:

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/SFML/SFML 2.0 Build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/SFML/SFML 2.0 Build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Configuring incomplete, errors occurred!

I have tried to remedy them myself by double checking that the cmake variable is set, trying different generator types, and, of course, googling some of them.

20
General / SFML Compiling
« on: February 11, 2012, 08:09:24 pm »
Hello there.  I have been attempting to update my SFML to 2.0, but have run into quite a few problems.  Even after carefully reading the tutorial provided on this site, watching youtube tutorials, and doing multiple google searches, cmake seems to hate me :(  Is there a pre-compiled version of SFML 2.0 for a Windows Vista system using the Codeblocks IDE?

21
Graphics / Movement and Views
« on: February 10, 2012, 10:30:14 pm »
I dont mean to rush you Laurent, but any progress with this?

22
Graphics / Movement and Views
« on: February 08, 2012, 11:18:15 pm »
Alright, thanks ;)

23
Graphics / Movement and Views
« on: February 08, 2012, 01:57:17 pm »
I want the background to stay still while the sprite can move around, with the view staying constantly centered on the sprite.  I was able to get the player to move around just fine until I added the code for views though...

Quote
The view stays on the play(er) well, however, the player cannot move outside of the initial area that was first viewed. To say that another way, the player cant move outside of the initial 800, 600 window area.


And the view itself doesnt stay center on the sprite, even though the code says too.

Code: [Select]
View.SetCenter(Cursor.GetPosition().x, Cursor.GetPosition().y);

24
Graphics / Movement and Views
« on: February 07, 2012, 10:15:48 pm »
Doing:
Code: [Select]
App.SetView(App.GetDefaultView());
       
        App.Draw(Background);


or:
Code: [Select]
App.Draw(Background);

        App.SetView(View);


Both result in nothing moving at all, or at least, not seeming to move at all.

25
Graphics / Movement and Views
« on: February 07, 2012, 04:36:39 pm »
I did as you suggested, even used the example code in the documentation, but the problem still persists.  The sprite, in this case Cursor, doesnt go outside of the initial window area and the view doesnt stay centered on the sprite.

Code I am using:
Code: [Select]
int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Views");

    sf::Image BackgroundImage;
    if (!BackgroundImage.LoadFromFile("background.png"))
        return EXIT_FAILURE;
    sf::Sprite Background(BackgroundImage);

    sf::Image CursorImage;
    if (!CursorImage.LoadFromFile("player.png"))
        return EXIT_FAILURE;
    sf::Sprite Cursor(CursorImage);

    Background.Resize(2000, 2000);

    sf::Vector2f Center(1000, 1000);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);

    Cursor.SetCenter(32, 32);
    Cursor.SetPosition(Center);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
        Cursor.SetPosition(CursorPos);

        View.SetCenter(Cursor.GetPosition().x, Cursor.GetPosition().y);

        App.SetView(View);

        App.Draw(Background);

        App.Draw(Cursor);

        App.SetView(App.GetDefaultView());

        App.Display();
    }

    return EXIT_SUCCESS;
}

26
Graphics / Movement and Views
« on: February 07, 2012, 03:49:22 pm »
So I have been messing around with sf::View recently (SFML 1.6) and made the simple program below:

Code: [Select]
#include <SFML/Graphics.hpp>

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Sprite Test");
     sf::Image ForestTileImg;
     sf::Image PlayerImg;

     if(!ForestTileImg.LoadFromFile("forest_terrain_tile.png")) {
        return EXIT_FAILURE;
     }
     if(!PlayerImg.LoadFromFile("player.png")) {
        return EXIT_FAILURE;
     }

     ForestTileImg.SetSmooth(false);
     PlayerImg.SetSmooth(false);

     sf::Sprite PlayerObj(PlayerImg);
     sf::Sprite ForestTileObj(ForestTileImg);
     ForestTileObj.SetPosition(400,300);
     PlayerObj.SetPosition(400, 300);

    float NewX = 400;
    float NewY = 300;

    sf::Vector2f Center(800, 600);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
            {
            NewX = App.GetInput().GetMouseX();
            NewY = App.GetInput().GetMouseY();
            }

         PlayerObj.SetPosition(NewX, NewY);

         View.SetCenter(NewX, NewY);

         App.SetView(View);
         App.Clear();

         App.Draw(ForestTileObj);
         App.Draw(PlayerObj);

         App.Display();
     }
     return EXIT_SUCCESS;
 }


The view stays on the play well, however, the player cannot move outside of the initial area that was first viewed.  To say that another way, the player cant move outside of the initial 800, 600 window area. Suggestions?

27
Graphics / Views and Movement
« on: February 06, 2012, 03:59:04 am »
So I have been messing around with sf::View recently (SFML 1.6) and made the simple program below:

Code: [Select]
#include <SFML/Graphics.hpp>

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Sprite Test");
     sf::Image ForestTileImg;
     sf::Image PlayerImg;

     if(!ForestTileImg.LoadFromFile("forest_terrain_tile.png")) {
        return EXIT_FAILURE;
     }
     if(!PlayerImg.LoadFromFile("player.png")) {
        return EXIT_FAILURE;
     }

     ForestTileImg.SetSmooth(false);
     PlayerImg.SetSmooth(false);

     sf::Sprite PlayerObj(PlayerImg);
     sf::Sprite ForestTileObj(ForestTileImg);
     ForestTileObj.SetPosition(400,300);
     PlayerObj.SetPosition(400, 300);

    float NewX = 400;
    float NewY = 300;

    sf::Vector2f Center(800, 600);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
            {
            NewX = App.GetInput().GetMouseX();
            NewY = App.GetInput().GetMouseY();
            }

         PlayerObj.SetPosition(NewX, NewY);

         View.SetCenter(NewX, NewY);

         App.SetView(View);
         App.Clear();

         App.Draw(ForestTileObj);
         App.Draw(PlayerObj);

         App.Display();
     }
     return EXIT_SUCCESS;
 }


The view stays on the play well, however, the player cannot move outside of the initial area that was first viewed.  To say that another way, the player cant move outside of the initial 800, 600 window area. Suggestions?

28
Graphics / Dragging Sprite outside original position
« on: January 26, 2012, 04:43:39 pm »
Thanks man. That fixed it :)

Edit:  So how would I do the following as well?
Quote
Another problem I am having is figuring out how to make it so that, if the mouse button is down and then the cursor is rolled over the sprite, it moves it. Is there a way to make it so that that doesnt happen? So that if Sprite1 is being dragged over Sprite2, then Sprite2 is also not dragged along with Sprite1.

29
Graphics / Dragging Sprite outside original position
« on: January 26, 2012, 01:55:18 am »
So I have found quite a few topics on this in the forums, but have not been able to implement a successful solution to the problem.  When holding down the mouse button over the sprite, it moves, but only as far as the parameters of the original sprite's position(somewhere around 35 pixels it seems). Another problem I am having is figuring out how to make it so that, if the mouse button is down and then the cursor is rolled over the sprite, it moves it.  Is there a way to make it so that that doesnt happen? So that if Sprite1 is being dragged over Sprite2, then Sprite2 is also not dragged along with Sprite1.  Any help is much appreciated :)

Oh, and below is my current code for dragging a single sprite.

Code: [Select]
#include <SFML/Graphics.hpp>

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Dragging Test");

     sf::Image SpriteImg;
     if (!SpriteImg.LoadFromFile("sprite.png"))
         return EXIT_FAILURE;
     sf::Sprite SpriteObj(SpriteImg);
     SpriteObj.SetPosition(365, 265);
     SpriteImg.SetSmooth(false);

     float XPosSprite = SpriteObj.GetPosition().x;//the x position of the panel
     float YPosSprite = SpriteObj.GetPosition().y;//the y position of the panel
     float XSizeSprite = SpriteObj.GetSize().x;//the width of the panel
     float YSizeSprite = SpriteObj.GetSize().y;//the height of the panel

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }
         if(App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
         {
             float MouseX = App.GetInput().GetMouseX();
             float MouseY = App.GetInput().GetMouseY();

             if((MouseX >= XPosSprite && MouseX <= XPosSprite+XSizeSprite && MouseY >= YPosSprite && MouseY <= YPosSprite+YSizeSprite) == true)
             {
                 SpriteObj.SetPosition(MouseX - (XSizeSprite / 2), MouseY - (YSizeSprite / 2));
             }
         }
         App.Clear();
         App.Draw(SpriteObj);
         App.Display();
     }
     return EXIT_SUCCESS;
 }

30
Graphics / Sprite Movement on Single MouseClick
« on: January 18, 2012, 01:32:39 am »
Ah, thank you for that lol Little embarrassing to miss a little colon. It is nearly perfect guys, thank you very much. However, the player now only moves if the mouse button is held down, even though the PlayerObj.SetPosition command is outside of the if statement:
Code: [Select]
   sf::Vector2f Origin = PlayerObj.GetPosition();
    sf::Vector2f Destination = Origin;
    sf::Vector2f Direction = Destination - Origin;
    float Speed = .5f;

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }
         App.Clear();

         if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
            {
            float NewX = App.GetInput().GetMouseX();
            float NewY = App.GetInput().GetMouseY();
            Origin = PlayerObj.GetPosition();
            Destination = sf::Vector2f (NewX, NewY);
            Direction = Destination - Origin;
            float Distance = sqrt( (Destination.x - Origin.x) * (Destination.x - Origin.x) + (Destination.y - Origin.y) *  (Destination.y - Origin.y) );
            Direction /= Distance;
            }
         PlayerObj.SetPosition(Origin + Direction * Speed);

Pages: 1 [2] 3 4
anything