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 - Chay Hawk

Pages: 1 ... 5 6 [7]
91
Graphics / Is there a way to take a capture of the map width and height?
« on: August 20, 2014, 03:17:46 pm »
Ok so what I want to do is save an image of the entire map to a file. The problem im having is it only saves what is shown in the window, I want it to save the entire height and width of the map not the window. I'm a bit unsure on how to go about doing this though, if it's even possible.

92
Window / Re: Window won't show when passed from struct
« on: August 18, 2014, 06:30:47 am »
nevermind I got it, finally after 45 minutes.

93
Window / Re: Window won't show when passed from struct
« on: August 18, 2014, 06:22:59 am »
ah, i see, so what do I put in it? when I try to do:

str.window.create(str.vidM(700, 800), str.window.setTitle("window"));

It gives me errors

C:\Users\thund_000\Desktop\Pass Render Wimdpw\main.cpp|34|error: no match for call to '(sf::VideoMode) (int, int)'|

94
Window / Window won't show when passed from struct
« on: August 18, 2014, 06:11:19 am »
I am trying to put my window in a struct, I made this file as a test as my other file was huge, the program compiles but the window never appears, what's going wrong?

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

using namespace std;

struct Str
{
    Str(sf::RenderWindow& window, sf::VideoMode& vidM);

    sf::RenderWindow& window;
    sf::VideoMode& vidM;
};

Str::Str(sf::RenderWindow& window, sf::VideoMode& vidM): window(window), vidM(vidM)
{

}

void MAIN(Str &str);

int main()
{
    sf::RenderWindow win;
    sf::VideoMode vMode;

    Str str(win, vMode);

    MAIN(str);
}

void MAIN(Str &str)
{
    str.window;
    str.vidM.height = 800;
    str.vidM.width = 600;
    str.window.setTitle("Window");

    while(str.window.isOpen())
    {
        str.window.clear();
        sf::Event event;
        while(str.window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                {
                    str.window.close();
                }
            }
        }
        str.window.display();
    }
}
 

95
General / Re: Collision help
« on: August 16, 2014, 01:26:31 pm »
Well i've been doing that, i try to get the left and right sides and top and bottom and I do get those things so that's not a problem but when i touch the square it sometimes acts like its slippery and goes around it, also if Im pressing a key and then press another direction key it will go to one of the corners of the square. other than that it does collide, so what could be going wrong and how can I fix it?

96
General / Collision help
« on: August 16, 2014, 06:59:23 am »
I am making some collision and it sort of works but it's not working as good as it should, its hard to explain but if you run the code you'll see what i mean.

Collision

//Get collision.
        if(rectToMove.intersects(redBlockSprite.getGlobalBounds()))
        {
            if(velocity.x < 0 && position.x < redBlockSprite.getPosition().x + redBlockSprite.getGlobalBounds().width)
            {
                cout << "Touched Right side" << endl;
                position.x = redBlockSprite.getPosition().x + characterSprite.getGlobalBounds().width;
            }
            if(velocity.y > 0 && position.y > redBlockSprite.getPosition().y - redBlockSprite.getGlobalBounds().height)
            {
                cout << "Touched Top" << endl;
                position.y = redBlockSprite.getPosition().y - characterSprite.getGlobalBounds().height;
            }

            if(velocity.x > 0 && position.x > redBlockSprite.getPosition().x - redBlockSprite.getGlobalBounds().width)
            {
                cout << "Touched Left Side" << endl;
                position.x = redBlockSprite.getPosition().x - characterSprite.getGlobalBounds().width;
            }
            if(velocity.y < 0 && position.y < redBlockSprite.getPosition().y + redBlockSprite.getGlobalBounds().height)
            {
                cout << "Touched Bottom" << endl;
                position.y = redBlockSprite.getPosition().y + characterSprite.getGlobalBounds().height;
            }
        }
 


Complete Code

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

using namespace std;

int main()
{
    sf::Vector2f position;
    sf::Vector2f velocity;
    float maxspeed = 4.0f;
    float accel = 4.5f;
    float decel = 0.01f;
    bool vSyncEnabled = true;

    //Setup Window and Framerate
    sf::RenderWindow window(sf::VideoMode(800, 600), "Bounding Box (Collision)");
    window.setFramerateLimit(60);
    window.setVerticalSyncEnabled(vSyncEnabled);

    //Load Texture
    sf::Texture character;
    if(!character.loadFromFile("Resources/Textures/triangle.png"))
    {
        cout << "Error loading resource 'triangle.png'" << endl;
    }
    else
    {
        cout << "triangle.png texture loaded" << endl;
    }

    //Set Sprite for Character Object
    sf::Sprite characterSprite;
    characterSprite.setTexture(character);
    characterSprite.setOrigin(sf::Vector2f(0, 0));
    characterSprite.setPosition(400, 300);

    //Load Red Block Texture
    sf::Texture redBlock;
    if(!redBlock.loadFromFile("Resources/Textures/RedBlock.png"))
    {
        cout << "Error loading 'RedBlock.png" << endl;
    }
    else
    {
        cout << "RedBlock.png texture loaded" << endl;
    }

    //Set Sprite for Red Block Object
    sf::Sprite redBlockSprite;
    redBlockSprite.setTexture(redBlock);
    redBlockSprite.setOrigin(sf::Vector2f(0, 0));
    redBlockSprite.setPosition(200, 200);

    while(window.isOpen())
    {
        window.clear(sf::Color::White);

        window.draw(characterSprite);
        window.draw(redBlockSprite);

        sf::Event event;

        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                {
                    window.close();
                }
                break;
                //Dont stretch the window contents when its resized
                case sf::Event::Resized:
                {
                    sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                    window.setView(sf::View(visibleArea));
                }
                break;
            }
        }

        //WASD Movement
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        {
            velocity.x -= accel;
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        {
            velocity.x += accel;
        }
        else
        {
            velocity.x *= decel;
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        {
            velocity.y -= accel;
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        {
            velocity.y += accel;
        }
        else
        {
            velocity.y *= decel;
        }

        //Make sure the sprite isn't going too fast
        if(velocity.x < -maxspeed) velocity.x = -maxspeed;
        if(velocity.x >  maxspeed) velocity.x =  maxspeed;
        if(velocity.y < -maxspeed) velocity.y = -maxspeed;
        if(velocity.y >  maxspeed) velocity.y =  maxspeed;

        //Update sprite position and move sprite
        position += velocity;

        //Get the window's size
        sf::Vector2u currWSize = window.getSize();

        if(position.x <= 0)
        {
            position.x = 0;
        }
        if(position.y <= 0)
        {
            position.y = 0;
        }
        if(position.x >= currWSize.x - characterSprite.getGlobalBounds().width)
        {
            position.x = currWSize.x - characterSprite.getGlobalBounds().width;
        }
        if(position.y >= currWSize.y - characterSprite.getGlobalBounds().height)
        {
            position.y = currWSize.y - characterSprite.getGlobalBounds().height;
        }

        sf::FloatRect rectToMove(position, {characterSprite.getGlobalBounds().width, characterSprite.getGlobalBounds().width});

        //Get collision.
        if(rectToMove.intersects(redBlockSprite.getGlobalBounds()))
        {
            if(velocity.x < 0 && position.x < redBlockSprite.getPosition().x + redBlockSprite.getGlobalBounds().width)
            {
                cout << "Touched Right side" << endl;
                position.x = redBlockSprite.getPosition().x + characterSprite.getGlobalBounds().width;
            }
            if(velocity.y > 0 && position.y > redBlockSprite.getPosition().y - redBlockSprite.getGlobalBounds().height)
            {
                cout << "Touched Top" << endl;
                position.y = redBlockSprite.getPosition().y - characterSprite.getGlobalBounds().height;
            }

            if(velocity.x > 0 && position.x > redBlockSprite.getPosition().x - redBlockSprite.getGlobalBounds().width)
            {
                cout << "Touched Left Side" << endl;
                position.x = redBlockSprite.getPosition().x - characterSprite.getGlobalBounds().width;
            }
            if(velocity.y < 0 && position.y < redBlockSprite.getPosition().y + redBlockSprite.getGlobalBounds().height)
            {
                cout << "Touched Bottom" << endl;
                position.y = redBlockSprite.getPosition().y + characterSprite.getGlobalBounds().height;
            }
        }

        characterSprite.setPosition(position);
        velocity *= decel;

        window.display();
    }

    return 0;
}
 

97
Graphics / What goes here?
« on: August 15, 2014, 11:02:27 pm »
Ok so i'm trying to make some collisions and im reading the API document and I see:

"sf::Vector2f point = ...;"

What goes after point?

98
General / Re: Code Blocks cant find Libraries
« on: August 13, 2014, 10:04:31 am »
Oh ok.

99
General / Re: Code Blocks cant find Libraries
« on: August 13, 2014, 10:00:58 am »
Yeah, it's the test code when you follow the instructions to set it up:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

100
General / Re: Code Blocks cant find Libraries
« on: August 13, 2014, 09:54:36 am »
Ok I forgot to take out lib in front of sfml, however I did that and I still get errors:

||=== Build: Debug in SFML Test (compiler: GNU GCC Compiler) ===|
\SFML-2.1\lib\sfml-graphics||No such file or directory|
\SFML-2.1\lib\sfml-window||No such file or directory|
\SFML-2.1\lib\sfml-system||No such file or directory|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


If I do JUST

sfml-graphics etc.

I get these errors:

||=== Build: Debug in SFML Test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|5|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|5|undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|6|undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|7|undefined reference to `_imp___ZN2sf5Color5GreenE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|7|undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|15|undefined reference to `_imp___ZN2sf6Window5closeEv'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|12|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|18|undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|18|undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|20|undefined reference to `_imp___ZN2sf6Window7displayEv'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|9|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
C:\Users\thund_000\Desktop\SFML Test\main.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
obj\Debug\main.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\SFML-2.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\SFML-2.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\SFML-2.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZN2sf5ShapeD2Ev'|
||=== Build failed: 20 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

101
General / Code Blocks cant find Libraries
« on: August 13, 2014, 09:01:31 am »
I don't understand what's going on here, I have Code Blocks 13.12 with MinGW, I downloaded the "GCC 4.7 TDM (SJLJ) - 64 bits" version of SFML and I followed the tutorial, here:

http://www.sfml-dev.org/tutorials/2.1/start-cb.php

exactly as it was shown and I get 3 errors. Here it what it says:

||=== Build: Debug in SFML Test (compiler: GNU GCC Compiler) ===|
\SFML-2.1\lib\libsfml-graphics||No such file or directory|
\SFML-2.1\lib\libsfml-window||No such file or directory|
\SFML-2.1\lib\libsfml-system||No such file or directory|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


What is wrong? I have Windows 8 64 bit.


Also here is this from the build log:

-------------- Build: Debug in SFML Test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\SFML-2.1\lib -o "bin\Debug\SFML Test.exe" obj\Debug\main.o   C:\SFML-2.1\lib\libsfml-graphics C:\SFML-2.1\lib\libsfml-window C:\SFML-2.1\lib\libsfml-system
mingw32-g++.exe: error: C:\SFML-2.1\lib\libsfml-graphics: No such file or directory
mingw32-g++.exe: error: C:\SFML-2.1\lib\libsfml-window: No such file or directory
mingw32-g++.exe: error: C:\SFML-2.1\lib\libsfml-system: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))


It says mingw32, do i need to download the 32 bit version of SFML?

Pages: 1 ... 5 6 [7]
anything