1 Replies - 268 Views - Last Post: 05 October 2012 - 01:02 PM Rate Topic: -----

#1 kornfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-October 12

SFML. Display problem. Reference issue?

Posted 05 October 2012 - 09:06 AM

module.h
#include <SFML/Graphics.hpp>
enum Znak
{
	Yellow,
	Red,
	Empty
};

enum Ramka
{
	Normal,
	Highlight
};

class Board
{
	
public:
	Board(sf::RenderWindow &App);

	void draw();
	void restart();
	sf::Color bcolor;
	sf::Color redColor;
private:
	Znak tablica[5][5];
	Ramka obramowanie[5][5];
	sf::RenderWindow &mywindow;

	
	sf::Color yellowColor;
	sf::Color emptyColor;
	sf::Color lineColor;
	sf::Color highlightColor;
	float radius;
	float outline;
	float spaceX,spaceY;
};


board.cpp
#include "module.h"

Board::Board(sf::RenderWindow &App) : mywindow(App)
{
	bcolor      = sf::Color::Color(0, 102, 153);
    redColor        = sf::Color::Color(214, 71, 0);
    yellowColor     = sf::Color::Color(235,235,0);
    emptyColor      = sf::Color::Color(224,224,224);
    lineColor       = sf::Color::Color(0, 51, 102);
    highlightColor  = sf::Color::Color(255, 153, 0);
	
	radius = 60.0;
	spaceY=radius/2.0;
	outline=radius/15.0;
	radius = radius - spaceY/2.0 - outline;
	spaceX=radius/3.0;
	restart();
}

void Board::restart()
{
	for(int i=0;i<=5;i++)
		for(int j=0;j<=5;j++)
		{
			tablica[i][j]=Empty;
			obramowanie[i][j]=Normal;
		}
}	

void Board::draw()
{
sf::Color fillColor;
sf::CircleShape circle(radius,30); 
circle.setOutlineColor(highlightColor);
circle.setFillColor(fillColor);
circle.setPosition(200, 200);
circle.setOutlineThickness(outline);
mywindow.draw(circle);
}


main.cpp
 #include <SFML/Audio.hpp>
 #include <SFML/Graphics.hpp>
#include "module.h"

int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
 
	 Board board(App);
 

     // Start the game loop
     while (App.isOpen())
     {
         // Process events
         sf::Event event;
         while (App.pollEvent(event))
         {
             // Close window : exit
             if (event.type == sf::Event::Closed)
                App.close();
         }
	 
         // Clear screen
         App.clear();
 
         // Draw the sprite
      board.draw();
	 
         // Update the window
         App.display();
     
	 }
     return EXIT_SUCCESS;
 }


So the thing is, compiler passes it without any warning or error BUT the screen shows up and crashes insantly. I did tried to change the definition of Board::draw() to Board::draw(sf::RenderWindow &window) and then pass a reference to my App window, and use window.draw() in board.cpp and then Board.draw(App) in main.cpp but still it didn't work. My friend tried to make a friend method in class sf::RenderWindow::draw() but with no succes either. So my question is, what am I doing wrong? I am using VS 2010 on Win 7 64b.

Btw. I was using this tutorial:http://redkiing.word...i-introduction/
Regards, Chris.

Is This A Good Question/Topic? 0
  • +

Replies To: SFML. Display problem. Reference issue?

#2 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1311
  • View blog
  • Posts: 4,504
  • Joined: 19-February 09

Re: SFML. Display problem. Reference issue?

Posted 05 October 2012 - 01:02 PM

Hi, you're trying to enter 36 values ...

20	void Board::restart()
21	{
22	    for(int i=0;i<=5;i++)
23	        for(int j=0;j<=5;j++)
24	        {
25	            tablica[i][j]=Empty;
26	            obramowanie[i][j]=Normal;
27	        }
28	}  




... into 5 x 5 arrays.

26	    Znak tablica[5][5];
27	    Ramka obramowanie[5][5];


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1