Skip to content

Installation

Modar Nasser edited this page Aug 29, 2020 · 9 revisions

There are 2 ways to use NasNas in your project.

  1. Copy the source files into your project folder
  2. Link the static or dynamic libraries

The game framework is still in development, that's why I don't recommend using the static or dynamic libraries


Setting the project

(tested on Window and Linux)

  • Make sure you have SFML2 installed
  • Clone the NasNas repository somewhere on your computer
  • Create somewhere else a new folder with the following hierarchy:
NewProject
  ├─ include          # contains header files
  └─ src              # contains source files
  • Copy NasNas/cmake to NewProject.
  • Copy NasNas/include/NasNas to NewProject/include.
  • Copy NasNas/src/NasNas to NewProject/include.
  • Copy the NasNas.h file to the NewProject folder.
  • Create the following CMakeLists.txt file in the NewProject folder :
cmake_minimum_required(VERSION 3.12)

project(NewProject)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)

if (WIN32)
    set(SFML_ROOT C:/SFML)    # specify here the install location of SFML
    set(SFML_STATIC_LIBRARIES TRUE)
    find_package(SFML COMPONENTS graphics audio PATHS ${SFML_ROOT}/lib/cmake/ )
else()
    find_package(SFML COMPONENTS graphics audio )
endif()

# the following variables can be set to FALSE to exclude the associated module
set(NASNAS_BUILD_RESLIB         TRUE)
set(NASNAS_BUILD_ECS            TRUE)
set(NASNAS_BUILD_TILEMAPPING    TRUE)
set(NASNAS_BUILD_UI             TRUE)

include(cmake/NasNas.cmake)

add_executable(NewProject
    NasNas.h ${NasNas_Src} ${NasNas_Inc}
    main.cpp
)

# Demo game target
target_include_directories(NewProject PRIVATE include)
target_link_libraries(NewProject sfml-graphics sfml-audio)
  • Create the following main.cpp in the NewProject folder :
// Minimal working example
#include "NasNas.h"

class Game : public ns::App {
public:
    Game() : ns::App("NewProject", 720, 480) {}
    void update() override {}
};

int main() {
    Game g;
    g.run();
    return 0;
}

Building the project

  • Make sure CMake is installed, configured and added to your PATH
  • Make sure your compiler is added to your PATH
  • Open a command prompt and run the following commands :
mkdir build && cd build
cmake ..
cmake --build . -j4

Running the application

If the build is successful, you should find the executable file under build/bin.