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

Pages: [1]
1
Okay, so here's the situation:
I have a Button class, containing sf::Text and a sf::RectangleShape and a sf::FloatRect, telling what part of the window it must cover. I need to draw it on 2 different windows and I want it to scale with those windows automatically. The thing is that virtual void draw is const, so I can't change the size of the RectangleShape and the Text while drawing.
So, currently I have 2 choices:
Either copy the text and rectangleshape to new ones and draw those, which is waste of performance and typing or
create a specific update function for this case and call it every time the windows get resized which may make my code a lot more messy and I need to track that for every single button I create, which may cause bugs.
So, I was wondering if there is an easier way to accomplish this or resort to the second option?

My current code:

in UI\Button.hpp
namespace UI
{
    class Button : public sf::Drawable, public sf::Transformable
    {
        private:
            sf::Text mText;
            sf::FloatRect mButtonSize;
            sf::RectangleShape mButtonRect;
            ...



           virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
           ...
    }
}

in UI\Button.cpp
void UI::Button::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.transform *= getTransform();

    sf::Vector2f tmp = sf::Vector2f(target.getView().getSize().x * mButtonSize.width, target.getView().getSize().y * mButtonSize.height);

    mButtonRect.setSize(tmp);                    //changing size causes error due to const
    mButtonRect.setPosition(target.getView().getSize().x * mButtonSize.left, target.getView().getSize().y * mButtonSize.top);


    mText.setCharacterSize(mButtonRect.getSize().y * mTextRelativeSize);

    target.draw(mButtonRect, states);
    target.draw(mText, states);
}

2
General / Problem with the SFML Game Development book
« on: February 15, 2015, 07:51:22 pm »
Hi all, it feels like forever since I last posted here.  :D
Anyways, I've recently purchased SFML Game Development and I have to say, it's really helpful and interesting to follow.  ;D
I've been trying to write down all the code in each chapter (with the assistance of the github source code) and it's been going well until a few hours ago.
I just finished Chapter 5 and, while it was a bit complicated to follow, I believe I got the gist of it...
After I read through the last pages of the chapter and wrote down all the code, I was faced with ~45 errors like this one:
obj\Debug\Application.o||In function `ZN11ApplicationC2Ev':|
D:\SFML projects\Book_PartV\Application.cpp|19|undefined reference to `State::Context::Context(sf::RenderWindow&, ResourceHolder<sf::Texture, Textures::ID>&, ResourceHolder<sf::Font, Fonts::ID>&, Player&)'
|
All of these errors are inside Application.cpp.

Full error log can be seen here: http://pastebin.com/vEsPtA1D

I've noticed that the errors are connected to class State and it's struct Context...and I've compared both State.cpp and State.hpp with the ones on github several times.
I've been searching for the problem for at least an hour and I couldn't find anything.

If anyone wants the sources, I'll upload them on Pastebin.
Everything is written on a clean installation of Code::Blocks and compiled on MinGW and GCC 4.9.2 on Windows 8.1.

3
Graphics / sf::Drawable and a cv-qualifier(what is this even?)
« on: March 06, 2014, 08:46:55 pm »
I've been trying to get into object oriented C++ for the last couple of weeks, so today I tried to start a project (that being a simple calculator  :P, everybody's gotta start somewhere). So, I made a simple Button class.
Basically, what I have in Button.h is:
class Button : public sf::Drawable
{
    private:
          sf::RectangleShape rect;
          virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
          .....
}
 
While in Button.cpp I have
void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw(rect, states);
}
 

The errors that pop up are:
D:\SFML projects\Calculator\Button.cpp|74|error: non-member function 'void draw(sf::RenderTarget&, sf::RenderStates)' cannot have cv-qualifier|
D:\SFML projects\Calculator\Button.cpp||In function 'void draw(sf::RenderTarget&, sf::RenderStates)':|
D:\SFML projects\Calculator\Button.cpp|76|error: 'rect' was not declared in this scope|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
   
Built with Code::Blocks(MinGW) and SFML 2.1 (32-bit SJLJ version).

I'm fairly certain I'm doing something wrong, so I'd like some help in understanding how sf::Drawable should be integrated into my class.

All help would be really appreciated.   :)

Full code(didn't find a spoiler tag, so I guess I'll have to leave it like this):

Button.h
#ifndef ADD_H
#define ADD_H
#include "SFML/Graphics.hpp"

class Button : public sf::Drawable
{
    bool markedflag;
    sf::RectangleShape rect;
    sf::Color unmarked, marked, clicked;
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
public:
    Button();
    Button(int x, int y, int a, int b);
    Button(sf::Vector2f a, sf::Vector2f b);
    Button(sf::IntRect a);

    void checkMouse(sf::Vector2f mous);

    void setRect ();
    void setRect (int x, int y, int a, int b);
    void setRect (sf::Vector2f a, sf::Vector2f b);
    void setRect (sf::IntRect a);

    void setColors (sf::Color col1, sf::Color col2, sf::Color col3);

    void updateColor ();
};

#endif

Button.cpp

#include "Button.h"

Button::Button()
{
    rect.setPosition(0, 0);
    rect.setSize(sf::Vector2f(0, 0));
}

Button::Button(int x, int y, int a, int b)
{
    rect.setPosition(x, y);
    rect.setSize(sf::Vector2f(a, b));
}

Button::Button(sf::Vector2f a, sf::Vector2f b)
{
    rect.setPosition(a);
    rect.setSize(b);
}

Button::Button(sf::IntRect a)
{
    rect.setPosition(a.left, a.top);
    rect.setSize(sf::Vector2f(a.width, a.height));
}

void Button::setRect()
{
    rect.setPosition(0, 0);
    rect.setSize(sf::Vector2f(0, 0));
}

void Button::setRect(int x, int y, int a, int b)
{
    rect.setPosition(x, y);
    rect.setSize(sf::Vector2f(a, b));
}

void Button::setRect(sf::Vector2f a, sf::Vector2f b)
{
    rect.setPosition(a);
    rect.setSize(b);
}

void Button::setRect(sf::IntRect a)
{
    rect.setPosition(a.left, a.top);
    rect.setSize(sf::Vector2f(a.width, a.height));
}

void Button::setColors(sf::Color col1, sf::Color col2, sf::Color col3)
{
    unmarked=col1;
    marked=col2;
    clicked=col3;
}

void Button::updateColor()
{
    if (markedflag==0) rect.setFillColor(unmarked);
    else if (markedflag==1) rect.setFillColor(marked);
    else rect.setFillColor(clicked);
}

void Button::checkMouse(sf::Vector2f mous)
{
    sf::Vector2f pos=rect.getPosition(), siz=rect.getSize();
    if (pos.x<=mous.x&&pos.y<=mous.y&&siz.x>=mous.x&&siz.y>=mous.y) {if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) markedflag=2;
                                                                     else markedflag=1;}
    else markedflag=0;

}

void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw(rect, states);
}
 

4
'Sup, forum.
Some of you may know that I've been learning programming in C++ and SFML for quite some time. Well, I managed to get a friend into it(ErikPetrov's his username here), as well, and we spent the last 3 hours(yeah, I know it isn't that much, but it's a first) making this simple game.

The plot: Coming soon

The goal: Collect as many gold pieces as you can. Currently the game has no end but we'll think of something :P .

Graphics by: Erik Petrov(made with GIMP and a Mouse)
Coding by: Iliya Manolov(me) and Erik Petrov (done on Code::Blocks and SFML)
Music by: No music yet

Changelog:
Alpha v0.1 - First Release

Future features:
A main and ingame menu
A shop for other skins
Some mobs to make the game less boring
and much more.

Download from: greedytruck.tk/download

5
Window / How do you make sf::RenderWindow work in my class' function?
« on: June 19, 2013, 10:17:06 pm »
The title says it all. I have a class with several private sf::Sprites(the parts of the body of the character) and a function to draw them in an animation embedded into the class. Pretty much I want a character select screen where the characters are a class and have a simple animation on each one of them. Since I want both the animation and the choice process to work at the same time, I'll need threads. But when I write something similar to this:
sf::Thread randum_thread(&player_spr::anim_standby(window), &human);
where player_spr is my class, anim_standby is my function and window is my, well, window ;D , I get an error.
Basically, I want to know how to make a thread calling a class' function with parameters.



Thanks in advance,
Ilman

6
Window / sf::Window+the create function=errors?
« on: May 20, 2013, 05:57:59 pm »
Hello to all,
I'm new here  :) and I have a small issue with SFML. Let's say I make a function that draws all my stuff on the window. Good, but if I use sf::RenderWindow in main, I get an error stating that no window was created at the point of the draw function in my function.
In that case I thought of making a global sf:Window and create it inside main. All compiles well until it hits a draw function in main. It then says
error: 'class sf::Window' has no member named 'draw'|.
I'm using CodeBlocks on Windows 7.


All help apreciated.

Pages: [1]