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.


Topics - LucasShadow

Pages: [1] 2
1
Window / window.display() Creates Memory Leak with VBOs
« on: October 21, 2012, 05:35:06 am »
I am having some issues with the memory with a very simple OpenGL application that I wrote to learn VBOs. The memory it uses readily increases the longer it is open.  Below is code the duplicates what I am seeing using Windows Task Manager:

   
#include <windows.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <SFML/Graphics.hpp>
#include <glew.h>
#include <gl/gl.h>
#include <gl/glu.h>

using namespace std;

class Scene {
public:
    void resize( int w, int h ) {
        // OpenGL Reshape
        glViewport( 0, 0, w, h );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluPerspective( 120.0, (GLdouble)w/(GLdouble)h, 0.5, 500.0 );
        glMatrixMode( GL_MODELVIEW );
    }
};
int main() {

    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test");

    ///Setup the scene, materials, lighting
    Scene scene;
    scene.resize(800,600);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
    glEnable(GL_COLOR_MATERIAL);
    glShadeModel(GL_FLAT);
    glEnable(GL_LIGHT0);
    float XL = .5, YL = .1, ZL = 1;
    GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
    GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
    GLfloat lightpos[] = {XL, YL, ZL, 0.};
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

    glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
    glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
    glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
    glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB");
    glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
    glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB");
    glMapBufferARB = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB");
    glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");

    ///Each vertex is in order for what is needed
    GLfloat vertices[] = { .5, .5, .5,  -.5, .5, .5,  -.5,-.5, .5,  .5, -.5, .5};

    GLuint VBOID;
    glGenBuffersARB(1, &VBOID);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, 48, vertices, GL_STATIC_DRAW_ARB);

    ///Start loop
    cout << "Starting" << endl;
    while( window.isOpen() ) {
        sf::Event event;
        while( window.pollEvent( event ) ) {
            if( event.type == sf::Event::Closed )
                window.close();
        }

        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(50.0, 1.0, 1.0, 50);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(5, 5, 5, 0, 0, 0, 0, 1, 0);

        glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
        glEnableClientState(GL_VERTEX_ARRAY);

        glVertexPointer(3, GL_FLOAT, 0, 0);
        glDrawArrays(GL_QUADS, 0, 4);

        glDisableClientState(GL_VERTEX_ARRAY);

        ///Reset env settings for SFML
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        window.display();
    }

    return 1;
}

 

Commenting out all event polling changes nothing. The window clearing doesnt seem to make a difference if I use window.clear() or opengl's clear function.

With further commenting out I was able to figure out that the one line of code, window.display(), is causing my memory leak. Its not much with the little bit of data I have, increases about 2,000 KB per second for me using Windows Task Manager to track the applications memory consumption.

2
Graphics / Sprites with Different Textures
« on: September 16, 2012, 12:26:59 am »
Hello. I have a need to change the texture of a sprite from one to another. Now that is easy to do with a simple .setTexture(texture). However, it seems that if the textures differ in size, there is a problem.

For example, if I initialize a sprite with a small texture and then change it to a large texture, only a portion of the large texture is assigned to the sprite, a portion exactly the same size as the smaller texture.
Small:

Large:


If I initialize the texture with a large texture and change it to a small texture, the small texture will display with horizonal and vertical lines;
Large:

Small:


Additionally, it seems that the sprite's dimensions can not be changed from what they are initialized to with the first texture. Is there a way to change the textures correctly and be able to force a resize of the sprite to the correct dimensions?

Info: large_texture is a 65 x 65 .jpg, small_texture is a 32 x 32 .jpg

Source code that replicates my problem, using SFML 2.0:
#include <windows.h>
#include <SFML/Graphics.hpp>

using namespace std;

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

     sf::Texture large_texture;
     large_texture.loadFromFile("res\\Items\\stone.png");
     sf::Texture small_texture;
     small_texture.loadFromFile("res\\Items\\stonedust.png");

     sf::Sprite sprite1;
     sprite1.setTexture(small_texture);//change to either small or large
                                       //for initializing
     bool UsingLargeTexture(false);

     while (App.isOpen())
     {
         if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
         {
             bool decision(false);
             if(UsingLargeTexture == true && decision == false)
             {
                 sprite1.setTexture(small_texture);
                 UsingLargeTexture = false;
                 decision = true;
             }
             if(UsingLargeTexture == false && decision == false)
             {
                 sprite1.setTexture(large_texture);
                 UsingLargeTexture = true;
                 decision = true;
             }
             Sleep(500);
         }

         App.clear();

         App.draw(sprite1);

         App.display();
     }

     return EXIT_SUCCESS;
 }
 

3
Window / [SOLVED] RenderWindow::PreserveOpenGLStates
« on: July 15, 2012, 07:51:12 pm »
I am still getting used to SFML 2.0 and was wondering how the 2.0 version of RenderWindow::PreserveOpenGLStates can be invoked to make sure that OpenGL content can work with SFML content so that this doesnt happen:



That white stuff is an sf::Text, and the green is a textured quad.  Im hoping that by preserving the OpenGLStates I can make the text appear as normal, but I can't find the appropriate reference in the 2.0 docs.

4
General / Mixing SFML with OpenGL
« on: June 18, 2012, 12:30:33 am »
I have been playing around with OpenGL with SFML and have run into a couple problems.  Minimal example:

#include <windows.h>
#include <SFML/Graphics.hpp>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>

using namespace std;

int main() {

    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL Testing Environment");

    ///Text to show coords
    sf::Text text("X Coord");
    sf::Text text2("Y Coord");
    sf::Text text3("Z Coord");

    text2.setPosition(0,30);
    text3.setPosition(0,60);

    ///OpenGL Commands
        glClearColor(0.2,0.7,0.9,0);
        glEnable(GL_DEPTH_TEST);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glViewport(0, 0, 800, 600);
        gluPerspective(120.0, (GLdouble)800/(GLdouble)600, 0.5, 500.0);
        glMatrixMode(GL_MODELVIEW);

    float x = -10, y = 10, z = -10;

    ///Main loop
    while (App.isOpen())
    {
        sf::Event Event;
        while (App.pollEvent(Event))
        {
            if (Event.type == sf::Event::Closed)
                App.close();
        }

        ///Clear the screen and create a reference sphere
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                glLoadIdentity();
        glColor3d( 1.0,0.0,0.0 );
        glutSolidSphere(1,30,30);

        ///Change the view with the arrow and W/S keys
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  x = x + .1;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) x = x - .1;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))  y = y + .1;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) y = y - .1;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))  z = z + .1;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) z = z - .1;

        ///Camera
        glLoadIdentity();
        gluLookAt(x,y,z, 0,0,0, 0,1,0);

        ///Change text with current coords and display
        std::stringstream stream1;
        stream1 << x;
        text.setString(stream1.str());

        std::stringstream stream2;
        stream2 << y;
        text2.setString(stream2.str());

        std::stringstream stream3;
        stream3 << z;
        text3.setString(stream3.str());

        App.pushGLStates();
        App.draw(text);
        App.draw(text2);
        App.draw(text3);
        App.popGLStates();

        App.display();
    }
        return EXIT_SUCCESS;
}
 

The first is that when I comment out the lines:

App.pushGLStates();
App.draw(text);
App.draw(text2);
App.draw(text3);
App.popGLStates();
 

Then the sphere appears very close to the camera. When I keep them in the code, the sphere appears far away. I think this has something to do with keeping GL context through SFML, but I am not sure.

The second problem may not be meant for these forums, but I'll ask anyway just in case. The code provided above is supposed to create a sphere, which it does, and then should allow the user to move the camera's position around using the arrow and W/S keys. However, while the coords change, the view does not.

Any help at all would be much appreciated :)

5
Graphics / Cant use Vectors for RenderTextures?
« on: May 31, 2012, 06:27:34 am »
I am trying to make an array of rendertextures using vectors (with SFML 2.0), but I am getting some odd errors involving:

sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)' is private
 
 

Is using a vector not possible for what I am trying to do? Below is a minimal example that reproduces the errors:

#include <SFML/Graphics.hpp>

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

     ///Number of chunks along the x and y axis of the map
     int NumberOfChunks = 3;

     ///Vector for the rendertexture
     std::vector<sf::RenderTexture> bg; bg.resize(NumberOfChunks * NumberOfChunks);

     ///Create the size of the rendertexture
     for(int i = 0; i < NumberOfChunks * NumberOfChunks; i++) bg[i].create(3, 3);

     ///Some code here that assigns stuff drawn to the rendertextures

     ///Display the rendertextures
     for(int i = 0; i < NumberOfChunks * NumberOfChunks; i++) bg[i].display();

     ///Assign the rendertextures to sprites
     std::vector<sf::Sprite> WorldChunk; WorldChunk.resize(NumberOfChunks * NumberOfChunks);

     ///Some code here the positions the sprites

     while (App.isOpen())
     {
         sf::Event Event;
         while (App.pollEvent(Event))
         {
             if (Event.type == sf::Event::Closed)
                 App.close();
         }

         App.clear();

         ///Display the sprites
         for(int i = 0; i < NumberOfChunks * NumberOfChunks; i++) App.draw(WorldChunk[i]);

         App.display();
     }
     return EXIT_SUCCESS;
 }
 

6
Graphics / Understanding .getGlobalBounds().contains
« on: May 27, 2012, 02:45:05 am »
What is strange is that the following works:

if(Sprite1.getGlobalBounds().intersects(Sprite2.getGlobalBounds())) {//Do something}
 

But not something like:

if(Sprite1.getGlobalBounds().contains(Sprite2.getGlobalBounds())) {//Do something}
 

But get the error:
no matching function for call to 'sf::Rect<float>::contains(sf::FloatRect)'

Am I using the contain function incorrectly? And does the contain function just look for Sprite2 being within Sprite1 or does it also look for intersecting?  I ask because I want to have an if statement that turns true if a sprite is within or intersecting another sprite.

7
Graphics / sf::RenderTexture positioning?
« on: May 24, 2012, 05:31:12 am »
I am creating a simple tile generator using sf::RenderTexture and have run into an odd problem.  The below code (minimal example) should produce a nice small patch of grass, but nothing appears but a blank screen.  Am I using the rendertexture incorrectly or is this a bug?

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Upgrading to SFML 2.0 Testing Environment");

     sf::Texture grassimg;
     if(!grassimg.loadFromFile("img\\Terrain\\new_grass_tile.png")) {cout << "Error" << endl;};
     sf::Sprite Tile(grassimg);
     Tile.setPosition(0,0);

     float GridX = 3, GridY = 5, CountX = 0, CountY = 0, Iso = 0;
     float TileX = grassimg.getSize().x;
     float TileY = grassimg.getSize().y;
     sf::RenderTexture bg;
     bg.create(800, 800);

     for(int i = 1; i < GridX * GridY + 1; i++)
     {
         Tile.setPosition((TileX * CountX) + (TileX/2 * Iso), (TileY/2) * CountY);
         bg.draw(Tile);

         CountX++;
         if(CountX > GridX + 1 && Iso == 0) CountX = 0, CountY++, Iso = 1;
         if(CountX > GridX + 1 && Iso == 1) CountX = 0, CountY++, Iso = 0;
     }

     sf::Sprite grassobj;
     grassobj.setTexture(bg.getTexture());
     grassobj.setPosition(0,0);

     while (App.isOpen())
     {
         sf::Event Event;
         while (App.pollEvent(Event))
         {
             if (Event.type == sf::Event::Closed)
                 App.close();
         }

         App.clear();

         App.draw(grassobj);

         App.display();
     }
     return EXIT_SUCCESS;
 }
 

8
System / Very low FPS
« on: May 22, 2012, 07:36:47 pm »
So I have been upgrading my game from SFML 1.6 to SFML 2.0 and have noticed that my FPS has dropped from over a hundred (frame rate not limited) to a constant FPS of 10 in SFML 2.0. Ive been browsing the forum for solutions and tried them.

I am not using any polling events for the joystick.

I have the same result in Release as in Debug.

Is there something in SFML 2.0 that drastically changes FPS performance from SFML 1.6? Because all I have done really is change the code to fit the syntax of SFML 2.0.

9
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.

10
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) ?

11
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]

12
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?

13
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?

14
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?

15
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;
 }

Pages: [1] 2
anything