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

Pages: [1]
1
General / Lethn's Programming Questions Thread
« on: June 20, 2013, 08:32:40 pm »
I thought instead of spamming the forum with new topics guys I'd just spam the one topic then that way everyone else can keep posting as normal. I didn't think I'd get this deep into programming but as I go through tutorials I've got more and more things to investigate, some stuff I just get on my own but other stuff like what I'm working on currently I need help with.

I'm looking at how to combine C++ and SFML so I can get a basic game running, so the obvious stuff like health or gold go up or down depending on what happens to the game. I understand the C++ code and I understand the SFML code for both of these functions but I'm of course running into problems combining the two because I'm not sure where to put it. I'm also getting these situations where the C++ code isn't liking my SFML objects very much and I suspect that's going to be because the two will be in conflict with each other somewhere so I need to experiment and find out what works.


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main ()
{

    sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )
    { }
    sf::Text lineone;

    lineone.setFont( arial );
    lineone.setCharacterSize ( 12 );
    lineone.setPosition ( 340, 280 );





    while (window.isOpen())
    {
        {
            using namespace std;
            int numberinput;
            lineone.draw ( "Type in a number: " )
            cin>> numberinput;
            cin.ignore();
            if ( numberinput < 10 ){
            lineone.draw ( "Death, you entered too low a number" );


            }
        cin.get();
        }

    sf::Event event;
    while (window.pollEvent(event))


{
 if (event.type == sf::Event::Closed)
 window.close();
}

        window.clear();
        window.draw ( lineone );
        window.display();

    }

    return 0;

}

I'm starting off with the basic C++ functions and combining them with the SFML text, I'm aware you could use SFML TextEntered but I want to be able to use all of my C++ functions rather than just a couple and getting stumped when I try to do something different.

2
General / sf::Text not declaring properly?
« on: June 20, 2013, 02:19:06 pm »
I wonder if I should just make a thread for all my queries here to be honest :P I'm trying not to spam the forum but I've run into annoying problem with sf::Text. I thought I'd try it out since I'm still working on the other problem in my head but I found that no matter what I try the command isn't declaring my objects properly.


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{

    sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )

    sf::Text lineone;

    lineone.setFont( arial );
    lineone.setString ( "SFML Text is working!" );
    lineone.setCharacterSize ( 12 );
    lineone.setPosition ( 400, 300 );





    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))


{
 if (event.type == sf::Event::Closed)
 window.close();
}

        window.clear();
        window.draw ( lineone );
        window.display();

    }

    return 0;

}

 

Quote
|15|error: 'lineone' was not declared in this scope

It's clearly complaining about me naming my text but the problem is I can't see where I've gone wrong, I think I need a fresh pair of eyes to just have a look over it. I've probably missed something really obvious like a typo or the way it's laid out.

3
General / Making SFML smoother and more accurate
« on: June 17, 2013, 04:13:32 pm »
I'm getting through the input commands and such as you'll all know looking at my posts  but one thing I'm finding quite annoying is how glitchy everything looks at the moment when I put the code in. I see different things like velocity in other peoples' code when it comes to input though again these all seem to be for 1.6 versions of SFML.

Are there commands out there that can help me with the problems I'm having? For instance, when I move with the keys my object sort of just blinks across the screen rather than move in a smooth way. There's that same sort of effect with camera command as well and so on. There's also this annoying thing where when it comes to my mouse input that the object the mouse cursor moves is away from the actual cursor as opposed to on it or in the centre.

4
General / How does MouseMoveEvent work exactly?
« on: June 11, 2013, 02:58:32 pm »
In my continuous mission of making more interactive stuff I'm having some difficulty understanding the way MouseMoveEvent works and I know this is what I'll need if I want to make things like buttons etc. I've been trying the usual methods other code uses but of course that isn't working.

Does anyone have know of any source code examples and such that show a basic button working for example? What I'm trying to do is to get the code to detect my mouse going over a sprite and then replacing it with another sprite when I click for example. I bet it's going to be one of those things where it just has a specific way of working to the other input commands and I've missed it completely.

Just so you know, I have looked at the documentation but of course it only explains the syntax and doesn't show it actually being used in a practical way which I think is why I'm having trouble understanding it.

5
I've had a lot of success and found it surprisingly easy to get keys set up in SFML but I'm currently struggling with the mouse commands, is it possible to get a basic point and click function going? I'm talking the type you see on RPGs like Diablo 2, click to move the sprite across the screen. All the drawing commands work fine for me and I can get what I want on the screen no problem. I realise the localPosition is the wrong command for what I want but I've hit a wall now with it and I'd appreciate some tips, I can get stuff to happen if I specify exact coordinates and such but I want the sprite to follow where the cursor goes.

Quote


    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

        sf::Vector2i localPosition = sf::Mouse::getPosition( window );

        if ( sf::Mouse::isButtonPressed( sf::Mouse::Left ) );

        {
            spritename1.move ( localPosition );
        }


        {
            if (event.type == sf::Event::Closed)
                window.close();
            }

        window.clear();
        window.draw( spritewasteland1 );
        window.draw ( spritename1 );
        window.display();

    }

    return 0;


Note: Oops! I think I may have found the solution already! Let me know if you can think of anything better though! I think I'm going to have to use some of this: http://www.sfml-dev.org/documentation/2.0/structsf_1_1Event_1_1MouseMoveEvent.php

Extra Note: Okay found that events are the things I need to look at carefully so I can understand the syntax better: http://sfml-dev.org/tutorials/2.0/window-events.php

6
General / Possible SFML configuration fix for Codeblocks users
« on: May 26, 2013, 11:43:30 am »
Okay, It took me awhile to figure it out but as the tutorial says Codeblocks seems to use the SJLJ version of SFML but I'll have a minor rant about that after showing people what to do and see if this helps fix this problem.

1) Download the GCC 4.7 TDM (SJLJ) version of SFML 2.0 ( NOT GCC 4.7 MinGW (DW2) - 32 bits ) and follow the tutorial as normal

2) Be sure to copy the .dll files to the saved codeblocks project folder that you have

Note: I did this without having to use CMake at all and in the end Codeblocks seems to work fine with the SJLJ version of SFML 2.0, I was getting .dll errors and entry procedure errors until I tried this.

I followed these steps myself having had an annoying number of problems getting it to work after following the tutorial normally, to an absolute beginner the SJLJ/DW2 business isn't very clearly explained. I looked in MINGW's Bin folder and found libgcc_s_sjlj-1.dll and libgcc_s_dw2-1.dll files and just through randomness I tried downloading the SJLJ version instead and followed the steps again. It worked and so far there hasn't been any crashes or error messages.

What I want to know is, why are there are two .dll files in this folder when there are only supposed to be one? And why does Codeblocks default to the SJLJ version? None of this is explained in the tutorial and it's clearly frustrating a lot of newbies, I think the only reason I solved this is because of my random tinkering.

Let me know if this solution works for those using Codeblocks.

Pages: [1]