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

Pages: [1]
1
As soon as i debug and run the code it crashes on instant and i dont know why. Could someone help me!

Main
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Audio/Music.hpp>
#include <iostream>
#include "mainMenu.h"
int main()
{

        sf::RenderWindow window( sf::VideoMode( 600, 600 ), "RPG" );

    mainMenu menu(window.getSize().x, window.getSize().y);

    sf::Music menuMus;
    if (!menuMus.openFromFile("battletheme.wav"))
            std::cout<<"Sound file not found"<<std::endl;

//menuMus.setVolume(25);
//menuMus.setLoop(true);
 // menuMus.play()

        while ( window.isOpen( ) )
        {
                sf::Event event;

                while ( window.pollEvent( event ) )
                {
                        switch ( event.type )
                        {
                        case sf::Event::Closed:
                                window.close( );

                                break;
                        }
                }

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

mainMenu.cpp
#include "mainMenu.h"

mainMenu::mainMenu(float width, float height)
{
    if(!font.loadFromFile("arial.ttf"))
    {
        //handle error
    }

    menu[0].setFont(font);
    menu[0].setColor(sf::Color::Red);
    menu[0].setString("Play");
    menu[0].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));

    menu[1].setFont(font);
    menu[1].setColor(sf::Color::White);
    menu[1].setString("Options");
    menu[1].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));

    menu[2].setFont(font);
    menu[2].setColor(sf::Color::White);
    menu[2].setString("Exit");
    menu[2].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *3));
}
   ;

   void mainMenu::draw(sf::RenderWindow &window){
    for(int i=0; 1< MAX_NUMBER_OF_ITEMS; i++)
    {
        window.draw(menu[i]);
    }
   }
 

mainMenu.h
#ifndef MAINMENU_H
#define MAINMENU_H
#include "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#define MAX_NUMBER_OF_ITEMS 3
#pragma once
class mainMenu
{
    public:
        mainMenu(float width, float height);
        mainMenu();

        void draw(sf::RenderWindow &window);
        void MoveUp();
        void MoveDown();

    private:
        int selectedItemIndex;
        sf::Font font;
        sf::Text menu[MAX_NUMBER_OF_ITEMS];
};

#endif // MAINMENU_H
 

Can someone help me solve this problem? ive been at it for 2/3 hours now and i think it might just be something really simple...

2
C / Problems with class files with SFML
« on: August 24, 2014, 12:24:35 pm »
I'm making a small SFML game called skelton town. (not skeleton (its a inside reference)) I have made a file called Player which i want to allow me to make the player, draw him and allow me to input the keyboard inputs for his movement. but when i include the header to allow me use the file in main nothing is drawn. But i get no actual errors. Can you guys help?

Main

#include<SFML/Graphics.hpp>
#include<iostream>
#include<SFML/Window/Keyboard.hpp>
#include "Player.h"
#include <cstdlib>
int main()
{
    sf::RenderWindow Window;
    Window.create(sf::VideoMode(1920, 1080), "Skelton Town", sf::Style::Fullscreen);
Player player;
     while(Window.isOpen())
    {
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
        case sf::Event::Closed:
         Window.close();
                 break;
            }

        }

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
    return 0;
   }
        Window.clear();
        Window.draw(player.getSprite());  // Key line here
        Window.display();
    }
}

Player.cpp

#include "Player.h"
#include<iostream>
#include<SFML/Graphics.hpp>
Player::Player()
{


 sf::Texture pTexture;
 sf::Sprite playerImage;
if(!pTexture.loadFromFile("Player.png",sf::IntRect(30,0,64,32)))
    std::cout<<"Error could not load player image"<<std::endl;
playerImage.setTexture(pTexture);

    }

 

Player.h

#ifndef PLAYER_H
#define PLAYER_H
#include<SFML/Graphics.hpp>

class Player
{
    public:
        Player();

        sf::Sprite& getSprite() {return playerImage;}

    private:
        sf::Texture pTexture;
        sf::Sprite playerImage;

};

#endif // PLAYER_H
 

Can Someone Help Me. And Tell me what i have done wrong.

Pages: [1]
anything