Jump to content

  • Log In with Google      Sign In   
  • Create Account

DeliciousThaiCosine

Member Since 15 Jun 2013
Offline Last Active Oct 22 2013 11:51 AM

Topics I've Started

Z-Layer change

03 October 2013 - 12:24 AM

In a 2D isometric game, the player can be either behind a tree or in front of the tree.

I understand that in order to implement something like that, I need to draw the objects that are furthest away first and the objects that are closest to the screen last, but I don't know how to express that in C++.

 

How do I change the draw order of the objects during run time?

Like, when the player starts out behind the tree and then walks in front of the tree then I need to change "draw tree before player" to "draw tree after player"

I don't know how to write that at all.

 

Please help

 

(I'm using SFML and C++)


Basic Game Loop Crash

24 September 2013 - 02:08 AM

Basically, I crashed my computer when I ran my code.

My friend told me the reason was probably due to something about overheating my comp somehow.

Later on I ran this code on my laptop and when I opened my task manager my CPU Usage was at 100%.

So I know I'm doing something horrifically wrong, but I don't know what.

 

Originally the code was all in the main function and it worked fine, but only when

I rewrote the code in the game class did the program became problematic. Please help

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <cctype>

class Game
{
    private:
        sf::RenderWindow m_window;
        sf::Vector2u m_windowSize;
        sf::View m_mainView;
        sf::Event m_event;
        sf::Clock m_clock;

        sf::CircleShape m_Player;
    public:
        Game();
        void run();
    private:
        void getImput();
        void updateLogic();
        void renderGraphics();
};

Game::Game()
    :m_windowSize(1024, 640)
    ,m_window(sf::VideoMode(m_windowSize.x, m_windowSize.y), "Title")
    {
        m_window.setFramerateLimit(100);

        m_Player.setRadius(40.f);
        m_Player.setPosition(30.f, 30.f);
        m_Player.setFillColor(sf::Color::Cyan);
    }

void Game::run(){
    while(m_window.isOpen()){
        getImput();
        sf::sleep(sf::milliseconds(5));
        updateLogic();
        renderGraphics();
    }
}

void Game::getImput(){
    while(m_window.pollEvent(m_event)){
        switch (m_event.type){
            case sf::Event::Closed:
                m_window.close();
                break;
            case sf::Event::KeyPressed:
                if(m_event.key.code == sf::Keyboard::F4){
                    //Resize Window
                    m_windowSize.x = 800;
                    m_windowSize.y = 600;
                    // Apply possible size changes
                    m_window.setSize(sf::Vector2u(m_windowSize.x, m_windowSize.y));
                    m_mainView = sf::View(sf::FloatRect(0.f, 0.f, m_windowSize.x, m_windowSize.y));
                    m_window.setView(m_mainView);
                }
                break;
            default:
                //idk
                break;
        }
    }
}

void Game::updateLogic(){
    //Update the Logic here
}

void Game::renderGraphics(){
    m_window.clear();
    m_window.draw(m_Player);
    m_window.display();
}

int main()
{
    //Game
    Game game;
    game.run();

    return 0;
}

Error is illogical

15 June 2013 - 06:49 PM

I started working on this project and I don't know what happened.

I tried to create an object and then use a simple setUp function, but it refused to work.

The object was created, however when I attempted to use the function it came up with the

error: 'X' does not name a type. After this I tried something much simpler.

int i;
i=10;

It came up with the error: 'i' does not name a type. If I just say instead that int i=10; then the error disappears.

Up to this point in time I've been self-taught so I've never heard of this before and I don't know what to call it.

How do I fix this and how did this even occur?


PARTNERS