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

Pages: [1]
1
Graphics / Re: Drawing a regularly updating line that changes
« on: May 21, 2015, 11:31:05 am »
Thanks so much. I had no idea mouse move existed.


2
Graphics / Drawing a regularly updating line that changes
« on: May 21, 2015, 11:15:24 am »
Im trying to make a program were theres one point at 150, 150 and another point being the cursors location.
And a line is drawn from one point to the second and it keeps updating.

However when I attempted to do this with the following code:
while (true)
        {
                while (window.pollEvent(mapEvent))
                {
                        if (mapEvent.type == sf::Event::MouseMoved)
                        {
                                sf::Vertex line[] =
                                {
                                        sf::Vertex(sf::Vector2f(mapEvent.mouseButton.x, mapEvent.mouseButton.y)),
                                        sf::Vertex(sf::Vector2f(150, 150))
                                };

                                window.clear(sf::Color::Black);
                                window.draw(line, 2, sf::Lines);
                                window.display();
                        }
                }
 

When I do this tho It doesnt work and the line is drawn from the first point to a completely different region.
Why is this happening could anyone shed any light on the cause of this problem?

Gif: http://imgur.com/DNxQErH

EDIt: Oops it didnt show my cursor.

3
Graphics / Re: Loading a file from a folder in the current directory.
« on: February 22, 2015, 02:27:41 am »
On windows, you can use this

#include <windows.h>

string getPath() {
    char buffer[MAX_PATH];
    GetModuleFileName( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\\/" );
    return string( buffer ).substr( 0, pos);
}
 

then write

Image img;
img.loadFromFile(getPath() + "\\myImg.png");
 

Thanks for this answer, although Im slightly hesitant as I would have thought there was a more concise way of doing it.

4
Graphics / Re: Loading a file from a folder in the current directory.
« on: February 22, 2015, 02:26:41 am »
Use a relative path like "./filename".

This does work for me unfortunately.

5
Graphics / Loading a file from a folder in the current directory.
« on: February 15, 2015, 09:37:33 am »
I would like to include an image that is in a folder in the current folder without including the full path using the loadFromFile() function.

How can I achieve this?
Thank you.

6
System / Re: sf::Clock doesnt appear to be functioning.
« on: February 03, 2015, 12:20:00 pm »
But eventCount is defined as 0 ? before the while loop.

7
System / sf::Clock doesnt appear to be functioning.
« on: February 03, 2015, 12:09:48 pm »
I am writing some code that will display a makeshift SplashScreen however the sf::Clock module doesnt appear to be working in the way that I had hoped.

I have run the following code:
        sf::Event splashEvent; 
        int eventCount = 0;

        sf::Clock timer;

        while (true)
        {

                if (eventCount == 0)
                {
                        window.clear(sf::Color::White);
                        window.draw(companyLogoSprite);
                        window.display();
                }
                else if (eventCount == 0 && timer.getElapsedTime().asMilliseconds() >= 10)
                {
                        printf("Hello/n");
                        timer.restart();

                        window.clear(sf::Color::White);
                        window.draw(companyLogoSprite);
                        window.display();
                }

                if (eventCount == 1)
                {
                        window.clear(sf::Color::White);
                        window.draw(gameLogoSprite);
                        window.display();
                }
                if (eventCount == 2)
                        return;

                while (window.pollEvent(splashEvent))
                {
                        if (splashEvent.type == sf::Event::EventType::KeyPressed
                                || splashEvent.type == sf::Event::EventType::MouseButtonPressed)
                                eventCount++;
                }
        }

And yet at no point has the console said "Hello". What am I doing wrong? I would be glad of assistance.

(Note that any recommendations on how I have gone about writing this are also very much appreciated)

8
General / Re: Left of '::' must be a class/struct/union
« on: November 22, 2014, 11:10:01 am »
Right sorry. Ill delete the thread. Can you recommend and books before I do so?

9
General / Left of '::' must be a class/struct/union
« on: November 22, 2014, 10:58:47 am »
I'm unsure if this the right place to ask this so forgive me if this is not supposed to be here but I keep getting the error in the title & despite many searches on the internet I have not been able to find the answer.

Here is the code it relates to:

Graphics.cpp:
#include "Graphics.h"
#include "AppWindow.h"

sf::Sprite g::loadSprite(sf::Texture texture, int ix, int iy, int cx, int cy)
{
}

void g::writeText(sf::Font fontType, const char textValue, const int textSize)
{
}

void g::drawSprite(sf::Sprite, int cx, int cy)
{
}
 

Graphics.h
#ifndef _GRAPHICS_H
#define _GRAPHICS_H

#include "SFML\Graphics.hpp"

class graphics
{
public:
        sf::Sprite loadSprite(sf::Texture texture, int rx, int ry, int ix, int iy);
        void writeText(sf::Font fontType, sf::Text text, const char textValue, const int textSize);
        void drawSprite(sf::Sprite, int cx, int cy);
} g;


#endif

I am very new to using this library as well as c++ so please humor me.
Thanks very much.

Once again sorry if this isn't the right place to put this.

Pages: [1]