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

Pages: [1]
1
General / Re: Syntax Help
« on: November 11, 2012, 06:45:47 am »
Thanks i'll have a fiddle with it and see what i can do :D

2
General / Syntax Help
« on: November 10, 2012, 06:19:17 am »
Hey

I need help with assign my window as a global with video mode. I can't seem to get the syntax correct.


I get this error:

Code: [Select]
error C2665: 'sf::VideoMode::VideoMode' : none of the 3 overloads could convert all the argument types
Not sure what i have to do to correct it. This is my script:

globals.h && globals.cpp:

//globals.cpp
#include <SFML/Graphics.hpp>
#include <string>

using namespace std;

std::unique_ptr<sf::RenderWindow> window;

//globals.h
#include <SFML/Graphics.hpp>

extern sf::RenderWindow* window;
 


Then my main.cpp has:

#include <SFML/Graphics.hpp>
#include <string>

using namespace std;

#include "globals.h"

int main()
 {


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

 

What am i doing wrong?

3
General / Re: Get mouse position without event
« on: November 09, 2012, 10:08:20 pm »
EDIT: Ah that did work i just changed it to an Else If and seems to do the trick :)

4
General / Get mouse position without event
« on: November 09, 2012, 09:59:25 pm »
Hey

I have a slight issue im stuck with .... i have a button which when the mouse hovers over the button the image changes - this works perfectly fine.

How ever if i add a button pressed event the button no longer thinks the mouse is hovering over it. I'm not sure why! It seems i can't do both events at the same time...

This is my event loop in my main loop:

        bool click = false;
        int mouseX;
        int mouseY;
    // Start the game loop
     while (window.isOpen())
     {
         // Process events
         sf::Event event;
         while (window.pollEvent(event))
         {
             if (event.type == sf::Event::Closed) {
                 window.close();
                         }else{
                                 if(event.type == sf::Event::MouseButtonPressed){
                                          click = true;
                                 }
                                 if(event.type == sf::Event::MouseMoved){
                                          mouseX = event.mouseMove.x;
                                          mouseY = event.mouseMove.y;
                                }
                         }
                 }

         // Clear screen
         window.clear();

           btn_quit.RenderBttn(window,mouseX,mouseY,button,button_on,click);
          window.display();
 


Basically if i do a mouseButtonPressed event - the mouse position seems to be lost. Any reason this could happen ?

EDIT: i did a quick check and what occurs. When i do a mouseButtonPressed event, the mouse position becomes 0 : 0, i don't know why how ever.

5
General / Re: Can't get my sprites to display
« on: November 09, 2012, 01:44:51 am »
It seems adding ,true made it work.

Although its super slow when i run it. Like mouse over takes a second or more to react to change the image. Very odd.

6
General / Re: AW: Re: AW: Can't get my sprites to display
« on: November 09, 2012, 01:28:24 am »
When you set the texture to the sprite, do you reset the texture rect?
sprite.setTexture(tex, true);
;)

Can you link me the documentation about that boolean wondering what it does.

EDIT:

Its working :D

7
General / Re: Can't get my sprites to display
« on: November 09, 2012, 01:19:44 am »
EDIT:

Sorry i got confused i set the texture the load function i don't have the boolean though:

        void load(sf::Texture& texture, sf::Sprite& sprite, const std::string& img) {
          if(texture.loadFromFile(img)){
                  sprite.setTexture(texture);
          }
        }
 

8
General / Re: Can't get my sprites to display
« on: November 09, 2012, 01:04:35 am »
Well i took out most of the code because i believe it was the class function causing the problem but here is the loop:

     while (window.isOpen())
     {
         // Process events
         sf::Event event;
         while (window.pollEvent(event))
         {
             // Close window : exit
             if (event.type == sf::Event::Closed) {
                 window.close();
                         } else if(event.type == sf::Event::MouseMoved){
                                 mouseX = event.mouseMove.x;
                                 mouseY = event.mouseMove.y;

                         }
                 }
 
         // Clear screen
         window.clear();
                // Draw the sprite BG
         window.draw(background);
                // Draw the sprite LOGO
                 window.draw(logo);

                 btn_quit.RenderBttn(window,mouseX,mouseY,button,button_on);
                 window.display();
}
 

And window is setup like this:

sf::RenderWindow window(sf::VideoMode(atoi(config["ResoX"].c_str()), atoi(config["ResoY"].c_str())), "SFML window");

9
General / Can't get my sprites to display
« on: November 09, 2012, 12:53:33 am »
Hey all,


 I just recently written a class for my sprites to display in my loop but it won't display, i don't get an error of any kind, and it doesn't fail to load the image so I'm lost to why it is not displaying them.


This is how i create the buttons in main():

//there are 2 buttons one for normal & one for mouse hover

 sf::Sprite button;
 sf::Texture button_t;
 sf::Sprite button_on;
 sf::Texture button_on_t;
 load(button_t,button_on,theme["Button"]);
 load(button_on_t,button_on,theme["Button_On"]);
 int width = button.getLocalBounds().width;
 int height = button.getLocalBounds().height;

Button btn_quit(350,450,width,height,"Quit Game");

In my loop i display it like so:

btn_quit.RenderBttn(window,mouseX,mouseY,button,button_on);


And this is the relevant class which deals with it all:

Button::Button(int x, int y, int w, int h, std::string cap)
{
    m_y = y;
    m_x = (x / 2) - ( w / 2 );
    m_w = w;
    m_h = h;
    caption = cap;
}

bool Button::IsIn( int mouseX, int mouseY )
{

    if (((mouseX > m_x) && (mouseX < m_x + m_w))
    && ((mouseY > m_y) && (mouseY < m_y + m_h ) ) ) {

        return true;
    } else {
        return false;
    }
}

void Button::RenderBttn(sf::RenderWindow& destination,int &mouseX, int &mouseY,sf::Sprite& button, sf::Sprite& button_on)
{
    sf::Sprite result;
    result = IsIn(mouseX,mouseY) ? button_on : button;      
    result.setPosition( m_x , m_y );
    destination.draw(result);
}
 

Any idea why it won't display? Even though i get no errors and the image is being loaded?

10
General / Re: I can't setup SFML 2.0
« on: November 06, 2012, 07:25:08 am »
Well first of all, why are you using Winmain? Just use main, Winmain isn't portable or standards compliant.

The problem is that you aren't linking to sfml-graphics or sfml-window.

I figured out the problem in the end :P I accidently left "all configurations" selected whilst i was setting it up.

11
General / I can't setup SFML 2.0
« on: November 06, 2012, 04:15:28 am »
I followed the tutorial to the letter but i got errors and am unsure what part i have got incorrectly.

I have the VS++ 2010 version and have added the image of the end result.



Please help me :)

Thanks

12
General / Setup issues
« on: March 05, 2012, 05:00:41 am »
I wouldn't know how to do that :P Still kinda new to using this application and a SDK

13
General / Setup issues
« on: March 04, 2012, 10:10:42 pm »
Hey

I followed the tutorial to set up my project but its not working =/

I use Visual Studio C++ 2010 Express.

I used the demonstrated code in the tutorial but i get a few errors which is as follows:

Code: [Select]

main.cpp(1): warning C4627: '#include <SFML/System.hpp>': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header

main.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header

main.cpp(13): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source


I'm assuming i messed up the setup of the project but i can't work out what i got wrong, the tutorial doesn't quite follow the way 2010 works, as they made changes in 2010 so i'm wondering if some one knows what my mistake is..

Pages: [1]