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

Pages: [1] 2
1
Okay...I didn't know that existed. Thanks man.  ;D

2
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);
}

3
General / Re: Problem with the SFML Game Development book
« on: February 15, 2015, 09:12:14 pm »
Make sure you do a full rebuild, so there are no old object files being used.
Next you nees to make sure that you include all the header files properly and at the right place. Especially pay attention to forward declared types.

If that doesn't help you'll have to provide the source code.
After checking through the files, included in the project, I noticed that State.cpp wasn't included...
I really hate it when these dumb mistakes happen and I can't find them for hours...sorry for the inconvenience.  :(

4
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.

5
General discussions / Re: SFML 2.2 tagged in repository
« on: December 11, 2014, 06:47:14 pm »
Android and iOS ports will not be part of this release, so there will not be tutorials for them yet.
What? Wasn't the release of SFML 2.2 intended to have the ports ready? ???
Either way, congrats.  ;D

6
Graphics / Re: sf::Drawable and a cv-qualifier(what is this even?)
« on: March 06, 2014, 10:38:06 pm »
And, as I was assuming, my mistake was incredibly dumb.   ;D
Thanks, everything works now.

7
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);
}
 

8
A new update approaches: The Menu update!(alpha v0.2)
Added main and in-game menu.
Download it from our site: greedytruck.tk
or directly from the download page: greedytruck.byethost17.com/download.html.

Also screenshots can be found here: greedytruck.byethost17.com/gallery.html

Next update: The shop will no longer be a useless button.

9
I'll re-do all textures in a couple of days. The current ones are just placeholders.
Also, I'll be lowering the diagonal speed since the truck has twice the speed then. Might even add basic acceleration.
The font on the upper-left was a bad choice by the other dev. We'll be using something cleaner and less transparent.
And I really like how the other dev put a house door instead of a normal car door. :D

10
Sorry 'bout that. Will upload a couple of screenshots tomorrow.
Basically, you are a truck that goes around the screen and collects a piece of gold.
Every time you touch said piece, it respawns in another place and your "Gold" counter goes up. That is...pretty much it.

11
I know, right?  ;D
That's why I linked it directly to the download page. Once it's in a little bit more bearable state, we'll make donations more visible. Of course, nobody's gonna donate now.  :D

12
'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

13
I tried doing it in a single thread, but it resulted in too many errors and making it multi-threaded could easily make the whole thing easier.
The choice process gets where the mouse is left-clicked and depending on that position it displays a text about the character that was clicked.
Since I want an animation for all the characters onscreen, it'd be easiest to make several threads, one for each character that draws that respective character onscreen instead of drawing everything in the main function.


Hope that answered your question.

14
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

15
Window / Re: sf::Window+the create function=errors?
« on: May 20, 2013, 10:14:03 pm »
Fixed it.
Of course, I forgot the style. Also that '&' before contextsettings in RenderWindow had to be removed.

Thanks for the help.

Pages: [1] 2
anything