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

Pages: 1 2 [3]
31
General / Photoshop layers for texture atlas
« on: July 23, 2017, 10:07:53 am »
Hey folks,

Turns out all my UI stuff won't fit in a single texture and I don't want to go over 2048, so I was wondering if it were possible with SFML read form different PSD layers? Even if possible, is it wise to use a single PSD file over 2 PNG files? I appreciate the help from seasoned devs.

32
General / getGlobalBounds().contains("mouse coordinates") not working
« on: June 07, 2017, 11:27:56 pm »
In the example below, I'm trying to print "COLLISION" when I mouseover the box sprite.

Even though the sprite position is set elsewhere, getGlobalBounds() thinks that it's centered on coordinates 0,0.

What am I doing wrong here?

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

class Box : public sf::Drawable, public sf::Transformable
{

public:

        sf::Sprite sprite;
        sf::Texture texture;

        void load()
        {
                texture.loadFromFile("box.png");
                sprite = sf::Sprite(texture);
                sprite.setTextureRect(sf::IntRect(0, 0, 420, 120));
                sprite.setOrigin(210, 60);
        }

private:

        virtual void draw(sf::RenderTarget& target, sf::RenderStates states)const
        {
                states.transform *= getTransform();
                states.texture = &texture;
                target.draw(sprite, states);
        }

};

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

        Box box;
        box.load();
        box.setPosition(300, 300);

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

                sf::Vector2f Mouse = window.mapPixelToCoords(sf::Mouse::getPosition(window));
                std::cout << "Mouse.x = " << Mouse.x << ", Mouse.y = " << Mouse.y << std::endl;

                if (box.sprite.getGlobalBounds().contains(Mouse))
                {
                        std::cout << "COLLISION!" << std::endl;
                }

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

        return 0;
}

33
General / 1.6 to 2.x help with shapes
« on: June 06, 2017, 09:56:04 pm »
How would these be converted to 2.x?

win.draw(sf::Shape::Rectangle(le.Blocks[0].fRect, sf::Color(255, 0, 0)));
rt.draw(sf::Shape(sf::Shape::Line(l.position, end, 1, l.color)));

le.Blocks is basically a vector of FloatRects.
l.position and end are Vector2fs

34
General / vector of Drawable AND Transformable
« on: June 01, 2017, 07:06:44 pm »
Hi, I'm trying to create a vector for objects from VARIOUS classes that all inherit from Drawable AND Transformable.

if I use

std::vector<std::reference_wrapper<const sf::Drawable>>

then I can't get their position with getPosition()

and if I use

std::vector<std::reference_wrapper<const sf::Transformable>>

then I can't draw them.

I need to be able to do both (getPosition AND draw).


35
General / Isometric Draw Order
« on: May 23, 2017, 07:59:44 pm »
Hey guys,

I'm making a tile-based isometric game (Diablo style) and I'm trying to tackle draw order.

At first I accomplished this by giving all entities a Z value depending on how many tiles there were between them and the player on the Y axis. With the game screen height being 1080p and my tile height being 60p, this resulted my dividing the screen into 18 "rows" or layers to be drawn from top to bottom. I then needed to repeat the following code 18 times with each entity:

if (random_entity.get_Z() == 18)
window.draw(random_entity);

This was crude and unmaintainable, so I looked around and found this: https://github.com/SFML/SFML/wiki/Tutorial:-Drawable-Group. What I did then was instead create 18 of these Group classes from the tutorial, add a "m_drawables.clear();" function to it and I constantly clear and push_back entities into these groups.

I then finally realized that I wouldn't have to use 18 different groups if I could somehow sort the entities according to their Y positions since whatever's higher on the screen should get drawn first anyway. Unfortunately I have no idea how to even begin implementing this.

From what I understand, the Group class uses a reference_wrapper to store the addresses of sf::drawables; and you use the push_back function to add drawables to it. I know that if it were a simple vector of ints I could just do:

std::sort(m_drawables.begin(), m_drawables.end());

... but it's a vector of objects and I have no idea how to sort the Y or Z values of these sf::drawables.

I hate asking others for code, but in this case at least we could add it to the tutorial. I'm a self-taught c++ enthusiast and I'm learning SFML as I make this game, so I really appreciate any help you can give me.

36
General / Problem moving the character to mouse coords
« on: April 05, 2017, 11:25:12 pm »
Hi folks

I'm making a grid based diablo-like game and I have a question to ask:

currently I'm using this for moving the player from tile to tile:

sf::Vector2f direction = sf::Vector2f(mouse.x, mouse.y) - player.getPosition();
float magnitude = sqrt((direction.x * direction.x) + (direction.y * direction.y));
sf::Vector2f unitVector(direction.x / magnitude, direction.y / magnitude);
player.move(unitVector * PlayerSpeed * elapsed_time.asSeconds());

the problem is - the player doesn't stop moving! ever!

I tried putting the last line in an if loop like - if player position != mouse coords - but couldn't make it work.

How do I make the player stop once it reaches the clicked tile (mouse.x and y)?


37
General / Can't get SFML to work in codeblocks
« on: January 21, 2017, 09:41:41 pm »
Here's what I have done so far, step by step:

1- downloaded codeblocks-16.01mingw-setup and installed it. codeblocks is working fine.

2- downloaded GCC 4.9.2 TDM (SJLJ) - 32-bit and put it in C:\SFML-2.4.1

3- created an empty project in codeblocks

4- went to Project -> Build Options.

selected the project name from the left menu so that the settings are global (applying to both Debug and Release).

added "C:\SFML-2.4.1\include" under Search Directories -> Compiler

added "C:\SFML-2.4.1\lib" under Search Directories -> Linker

said No to "Keep this as relative path?" on both occasions.

5- selected Debug from the left menu.

went to Linker Settings, added:

sfml-graphics-s-d
sfml-window-s-d
sfml-system-s-d

6- selected Release from the left menu.

went to Linker Settings, added:

sfml-graphics-s
sfml-window-s
sfml-system-s

7- selected the project name from the left menu (global settings)

went to Compiler Settings -> #defines and typed SFML_STATIC in the box.

8- clicked File -> New -> Empty File. Clicked Yes to add the file to the active project.

named it main.cpp and pasted the test code from http://www.sfml-dev.org/tutorials/2.4/start-cb.php into it.

When I run the program I get a ton of "undefined reference to ..." errors. too many to post here.

SFML website says I need to add the opengl32, freetype, jpeg, gdi32 and winmm dependencies under Linker Settings.

I tried this ordering for Debug and the same ordering without "-d"s for Release, but it DIDN'T WORK:

sfml-graphics-s-d
sfml-window-s-d
opengl32
freetype
jpeg
gdi32
sfml-system-s-d
winmm

in what EXACT ORDER do I need to add them?

Also, do I need to add other specific search directories for these to work?

Pages: 1 2 [3]
anything