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

Pages: 1 ... 3 4 [5]
61
SFML projects / Re: First real game project - current: menu template
« on: July 21, 2016, 07:20:41 pm »
@Hapax

Oh, forgot to mention that. :)
Green = done
Red = ongoing
Black = to come.

:)

62
To my knowledge, RenderWindow has no bounds, so you can render objects outside of the window, they will just not be displayed. Then move the View there, update it and then they will be displayed.

this topic talks a bit about it on the second reply (http://en.sfml-dev.org/forums/index.php?topic=17846.0)

so id just use RenderWindow as normal :) (i do this in my current project without any problems. all my items can move "out of bounds" as there are none. the View then just follows the "target" even at negative x and y coordinates.

63
Graphics / Re: Inconsistency in sf::Image::copy
« on: July 21, 2016, 04:21:09 pm »
since x_y coords in c++ goes like this:
--->
|
v

your first image shows the green image being added at a positive X and y coordinate on the red image
but the second shows it being added at a negative coordinate. said coordinate could be out of bounds for the image. (eg, you are trying to draw outside of the paper)

just my thoughts....

64
Hello SFML folks.

So, I've recently got a lot of extra time on my hands and my hands on some sfml books.
So, ive decided i wanted to give it a go at a game from scratch. my first major project on my own.

my background - an outdated webintegrator education from 2005, some Pacal, Turbo pacal, html, AS, AS2, java and java script, all at a low level mostly by hobby and free time.

gone trough all "making games with Ben" tutorials on youtube. (check thm out, you'll be glad you did)
read all of "SFML game devolopment by example" by R. Pupius (awesome book btw, can recommend, especial if a v. 2 comes out)

and this will be my devolopment log.

A demo can be downloaded here from my google drive:
https://drive.google.com/folderview?id=0B0wU233V6VHRZms3eGY4Y19acjA&usp=sharing
Latest update - Pre-Alpha : 28/7-16



About the game:
(click to show/hide)
The worksheet
(click to show/hide)

First video in spoiler:
(click to show/hide)


here is a video of my current progress
- 27/7-16 -



65
Window / Re: Render window and iterators / vectors
« on: July 20, 2016, 06:41:36 pm »
Nitpick: "_Btns" is, strictly speaking, not an allowed name. All names beginning with underscore and followed by a upper-case letter (as well as names containing double underscores "__" anywhere) arre reserved for the implementation. That is, only your compiler and standard library are allowed to use such names.

That is true. I've even reminded myself to fix it but forgot...
Thanks its fixed :)


If that's where the program breaks, it looks like it's the drawing of the sf::Text. I noticed that the actual font resource is stored in the button class. If the vector is re-arranged/re-located, the font is re-located and therefore the text points to the wrong location.

Ah, that did seem to be the problem...
the best solution i could find was to update the font each time i render the button, not the most elegant solution, but it works.

Thanks.

Solutions looks like this:

//in the memuFile
Quote
   
for (auto itr = _btns.begin(); itr != _btns.end(); ++itr) {
   itr->render(l_window, _font);
}

//in the button file
Quote
void ButtonTile::render(sf::RenderWindow& l_window, sf::Font& font) {
   _rect.setFillColor(_rCol);
   _txt.setFont(font);
   l_window.draw(_rect);
   l_window.draw(_txt);
}

66
Window / Re: Render window and iterators / vectors
« on: July 20, 2016, 04:51:41 pm »
Add more precisions. What do you mean by "doesn't work" ?

You are using a std::vector and a button that hold a texture. Since using push_back from std::vector asume copying the object, do you handle it correctly ? How do you handle texture in general ?

Showing your implementation of the class Button can be usefull for us.

Of course.

some Detail:
The error i get is:
Quote
Unhandled exception at 0x00147BDE in Platformer.exe: 0xC0000005: Access violation reading location 0x00000259.

added ///COMMENTS ON ERROR

The Code for ButtonTile (the button class) is:

Quote from: ButtonTile.h
#include <SFML\Graphics.hpp>
#include <string>

#pragma once

using namespace std;
class ButtonTile
{
public:
   ButtonTile();
   void init(int x, int y, string Txt, int cmd, sf::Font font);
   ~ButtonTile();

   void update(int x, int y);
   int TestPress();
   void render(sf::RenderWindow& l_window);


private:
   int _x, _y, _xSize, _ySize, _btnCmd;
   string _btnTxt;
   sf::Color _col, _rCol;
   sf::Text _Txt;
   sf::Font _Font;
   sf::RectangleShape _rect;
   bool _hover;
};



Quote from: ButtonTile.cpp
#include "ButtonTile.h"


ButtonTile::ButtonTile()
{
}


ButtonTile::~ButtonTile()
{
}


void ButtonTile::init(int x, int y, string Txt, int cmd, sf::Font font)
{

   _btnTxt = Txt;
   _x = x;
   _y = y;
   _xSize = (_btnTxt.length() * 8 )+3;
   _ySize = 23;
   _btnCmd = cmd;
   _col = sf::Color::Blue;
   _rCol = _col;
   _Font = font;
   _rect.setPosition(sf::Vector2f(_x, _y));
   _rect.setFillColor(_rCol);
   _rect.setSize(sf::Vector2f(_xSize, _ySize));
   _Txt.setFont(_Font);
   _Txt.setColor(sf::Color::White);
   _Txt.setPosition(sf::Vector2f(_x + 3, _y + 3));
   _Txt.setCharacterSize(15);
   _Txt.setString(sf::String(_btnTxt));
   _hover = false;
}

void ButtonTile::update(int x, int y)
{
   if (x > _x && x < _x + _xSize && y > _y && y < _y + _ySize) {
      _rCol = sf::Color::Black;
      _hover = true;
   }
   else {
      _rCol = _col;
      _hover = false;
   }
}

int ButtonTile::TestPress()
{
   if (_hover == true) {
      _rCol = sf::Color::Red;
      return _btnCmd;
   }
   else return 0;
}

void ButtonTile::render(sf::RenderWindow& l_window) {
   _rect.setFillColor(_rCol);
   l_window.draw(_rect);
   l_window.draw(_Txt);
/// <<<---- ACCESS VIALATION POINTS TO THIS END BARAK

And the menu that implements Button tile is:
Quote from: MenuFile.h
#include "ButtonTile.h"
#include <vector>

#pragma once

using namespace std;
class MenuFile
{
public:
   MenuFile();
   ~MenuFile();

   //Update functions, one gets info, other makes it it self.
   // int update(int x, int y, bool clicked, int current); //For later use
   void init(sf::Font font, string l_title);
   
   int update(int current, sf::RenderWindow& l_window);

   void addButton(string Txt, int cmd);

   void render(sf::RenderWindow& l_window);


private:
   int _nBtns;
   sf::RectangleShape _bg;
   vector<ButtonTile> _Btns;
   sf::Text _header;
   sf::Font _font;
};



Quote from: MenuFile.cpp
#include "MenuFile.h"


MenuFile::MenuFile()
{
}


MenuFile::~MenuFile()
{
}


void MenuFile::init(sf::Font font, string l_title) {
   _font = font;
   _header.setFont(_font);
   _header.setString(l_title);
   _header.setPosition(sf::Vector2f(130, 30));
   _header.setColor(sf::Color::White);
   _bg.setFillColor(sf::Color(100,100,130));
   _bg.setSize(sf::Vector2f(350, 90));
   _bg.setPosition(sf::Vector2f(25, 25));
}

int MenuFile::update(int current, sf::RenderWindow& l_window) {
   int updated = 0;
   ///THIS WORKS FINE///
   for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
      itr->update(sf::Mouse::getPosition(l_window).x / 2, sf::Mouse::getPosition(l_window).y / 2);
      if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
         updated = itr->TestPress();
         if (updated != 0) current = updated;
      }
   }

   return current;
}

void MenuFile::addButton(string Txt, int cmd) {
   _Btns.push_back(ButtonTile());
   _Btns.back().init(100, 70 + (_nBtns * 25), Txt, cmd, _font);
   _nBtns++;
   _bg.setSize(sf::Vector2f(350, 90 + (_nBtns * 25)));
}

void MenuFile::render(sf::RenderWindow& l_window) {
   l_window.draw(_bg);
   l_window.draw(_header);


   ///THIS WORKS FINE///
   _Btns.back().render(l_window);
   
   ///THIS DOES NOT WORK///
   for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
      itr->render(l_window);
   }
   
}

67
Window / SOLVED! Render window and iterators / vectors
« on: July 20, 2016, 02:56:46 pm »
So. i seem to have a small problem here.

I got a number of Buttons (a class i made) stored in a vector like so:
vector<Buttons> _Btns;

now, all _Btns members have been initialized. each contain a
sf rect
sf text
void render(sf::RenderWindow& l_window)
int update(int x, int y)

and some other functions and variables that are irrelevant to this problem.


now, i update the buttons like so:
Quote
int updated = 0;
for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
   itr->update(sf::Mouse::getPosition(l_window).x / 2, sf::Mouse::getPosition(l_window).y / 2);
   if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
      updated = itr->TestPress();
      if (updated != 0) current = updated;
   }
}

No problem there.

now, rendering gets a bit odd.

This works:
Quote
_Btns.back().render(l_window);
except that it only lets me render the last button added.

but this:

Quote
for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
   itr->render(l_window);
}
does not?

neither does:
Quote
_Btns.front().render(l_window);
Now, seeing as i can iterate with the update function, and I can render calling only the "back()"

I'm at a lost... what should i do to iterate and render my _Btns?

//I will get back with the answer if i find it first, but after 12 hours of google search I'm a bit done for!

//i know, the update function is not need in this example, it was just to show that one form works, another does not :S

68
SFML projects / Re: Screenshot Thread
« on: July 08, 2016, 11:27:03 am »
Hey nice thread... I think ill post a bit here..

So, im new to sfml (and simi new to c++)  got a book on it and started working. but as all eger people, i also experiment.

this is so simple that i do not think it deserves its own thread... yet.... but here it is.

1D war - inspired by "Making games with Ben" on youtube.








I plan to make this a fully functional game as a learning experience on my road to my goal/s :)

69
Ah yes, my suspicion was correct.
And while it is "unnecessary" in this regard, it is as you said a nice way to illustrate how to get a direction, I can see this used for multiple things, (fire back port weapons?)

and oh yea, i did not implement the code, but i see what you mean about the size-1, i always forget that i returns from 1+ and not 0+ as normal counting :)

any ways, still reading and glad to read it all :)

70
Thanks for the reply.

:) ah yes, i see it up there, and glad to see the solution was the same as mine:) (I'll be honest, i did only read the first 4 pages of the thread :)

About the snippets of code. well I do hope you get the chance to edit it in, or at least mention that setters/getters are left out, so that people will know that before hand... adding them will make the book more "beginner friendly" but then again, your target audience doe not seem to be the absolute beginner :)

one thing i was wondering.

in chapter 3, you have this piece of code:

Quote
void Snake::Extend() {
   if (m_snakeBody.empty()) { return; }
   SnakeSegment& tail_head = m_snakeBody[m_snakeBody.size() - 1];

   if (m_snakeBody.size() < 1) {
      SnakeSegment& tail_bone = m_snakeBody[m_snakeBody.size() - 2];
      if (tail_head.position.x == tail_bone.position.x) {
         if (tail_head.position.y == tail_bone.position.y) {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y + 1));
         }
         else {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y - 1));
         }
      }
      else if (tail_head.position.y == tail_bone.position.y) {
         if (tail_head.position.x > tail_bone.position.x) {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x + 1, tail_head.position.y));
         }
         else {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x - 1, tail_head.position.y));
         }
      }
   }
   else {
      if (m_dir == Direction::Up) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y + 1));
      }
      else if (m_dir == Direction::Down) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y - 1));
      }
      else if (m_dir == Direction::Left) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x+1, tail_head.position.y));
      }
      else if (m_dir == Direction::Right) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x-1, tail_head.position.y));
      }
   }
}

While its a nice little algorithm, and nice way of explaining how to find direction from two "objects" i do not see the point of it.

As the game is made i cant see there ever being a time where you are only 1 segment long (reset makes us 3 long) and since we move in tiles, i dont see why you place the new segment behind the last one.
I'd just do something like this:

Quote
void Snake::Extend() {
   int i = m_snakeBody.size();
   m_snakeBody.push_back(SnakeSegment(m_snakeBody[i ].x,m_snakeBody[i ].y));
}
This will place the new segment on top of the last one, allowing it to "pop out" whenever the snake moves next.

of course, the other way teaches us more, but seems a bit overkill for its functionality...

or am i lost here?

71
This look really awesome :)

Not only does it look good, but it also brings me hope for what i wanted to make... 14 days? thats incredible... Great work man :)

72
General / Re: Window
« on: July 04, 2016, 06:50:55 pm »
Hey man. yea,I've got the book too, and indeed, there are some missing snips of code here and there.

The GetRenderWindow being one of them.
The book never tells you to do it or even mentions it.

The code that i made to solve it:

in the Window header as public i made:

sf::RenderWindow* getRenderWindow();


and in the Window cpp i made:

sf::RenderWindow* Window::getRenderWindow() {
   return &m_window;
}


This is working for me... but I don't know if that was the intended goal?

73
Just got the book in by mail :)

Thanks a lot, looks good so far... just finished Chapter 2.
I'll admit, I've read other C++ books before, also on game creation, This one has its cons and pros if you ask me.

Chapter 1:
Pro:
Easy and straight forward, if you know your way around VC.
Con:
The setting up could use more attention to detail (page 5: Where do you put what in? C++/Linker and so far) the way it is now, you could just as well write a link to the SFML tutorial and a list over what to include.

Chapter 2:
Pro:
Fast intro to the "meat of stuff" and nice not to do 3 different "hello world" examples for once.
Con:
The code is still so short here that it could be include fully. leaving out " #include "SFML/Graphics.h"  "on page 20 & page 25, as well as cutting the Game Class Cpp and header down seems pointless to me.
All it did was letting me get more familiar with the error output window in VC


When all that is all said and done, i really liked the book so far and look forward to see what it will bring me.

Thanks for making it :)


-EDIT-

on to chapter 3:
*m_window.GetRenderWindow();

This function is required on page 55. it is not mentioned in the book.
A bit of hacking later and i have a solution:

in Window.h as a public function:

sf::RenderWindow* GetRenderWindow();

and in Window.cpp

sf::RenderWindow* Window::getRenderWindow() {
   return &m_window;
}


This works.

*Please note, the things i write is not meant to put you down from the book,its a first edition, i realize that and its still awesome. I hope to see a second edition with the different typos and left outs corrected.
Still awesome and keep it up.. also glad to see you interact with your readers :)

Pages: 1 ... 3 4 [5]
anything