Giter Site home page Giter Site logo

raylib-tileson's Introduction

raylib-tileson

Use Tiled maps in raylib, through Tileson.

raylib-tileson Example Screenshot

Example

#include "raylib.h"

#define RAYLIB_TILESON_IMPLEMENTATION
#include "raylib-tileson.h"

int main(int argc, char* argv[]) {
    InitWindow(800, 450, "[raylib-tileson] example");
    SetTargetFPS(60);

    // Load the map
    Map map = LoadTiled("resources/desert.json");

    while (!WindowShouldClose()) {
        BeginDrawing();
        {
            ClearBackground(RAYWHITE);

            // Draw the map
            DrawTiled(map, 0, 0, WHITE);
        }
        EndDrawing();
    }

    // De-Initialization
    UnloadMap(map);

    CloseWindow();
    return 0;
}

Dependencies

API

Map LoadTiled(const char* fileName);
Map LoadTiledFromMemory(const unsigned char *fileData, int dataSize, const char* baseDir);
bool IsTiledReady(Map map);
void DrawTiled(Map map, int posX, int posY, Color tint);
void UnloadMap(Map map);

Alternatives

While raylib-tileson does compile and run from C, it requires compilation with C++17. Mixing C and C++ may not be preferable by all, so there could be a desire to use an alternative...

Development

mkdir build
cd build
cmake ..
make
./example/raylib-tileson-example

License

raylib-tileson is licensed under the BSD 2-Clause License, see LICENSE for more information.

raylib-tileson's People

Contributors

dmlary avatar fatihcill avatar pkeir avatar robloach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

raylib-tileson's Issues

Runtime Error: New/Delete Type Mismatch with ASan

I'm using VCPKG to provide a few libraries for me, including raylib. The VCPKG debug libraries for raylib are linked with ASan and UBSan. Accommodating this, leads to a runtime error when I run raylib-tileson-example. (I am working on a fork here, with minor build system changes.) I can bypass using export ASAN_OPTIONS=new_delete_type_mismatch=0, but I thought you should know. Here is the error message:

INFO: TILESON: Map parsed successfully
=================================================================
==14721==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x611000011340 in thread T0:
  object passed to delete has wrong type:
  size of the allocated type:   216 bytes;
  size of the deallocated type: 8 bytes.
    #0 0x7ff58fac1530 in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:164
    #1 0x55dc75873653 in std::default_delete<tson::IJson>::operator()(tson::IJson*) const /usr/include/c++/12/bits/unique_ptr.h:95
    #2 0x55dc75867019 in std::unique_ptr<tson::IJson, std::default_delete<tson::IJson> >::~unique_ptr() /usr/include/c++/12/bits/unique_ptr.h:396
    #3 0x55dc7585db35 in tson::Tileson::~Tileson() /home/XXXXX/raylib-tileson/src/tileson.hpp:7444
    #4 0x55dc7584868b in LoadTiledFromMemory /home/XXXXX/raylib-tileson/src/raylib-tileson.cpp:109
    #5 0x55dc758487d4 in LoadTiled /home/XXXXX/raylib-tileson/src/raylib-tileson.cpp:121
    #6 0x55dc758474a2 in main /home/XXXXX/raylib-tileson/example/raylib-tileson-example.c:26
    #7 0x7ff58e82350f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #8 0x7ff58e8235c8 in __libc_start_main_impl ../csu/libc-start.c:381
    #9 0x55dc75847304 in _start (/home/XXXXX/raylib-tileson/build/example/raylib-tileson-example+0x2ff304)

0x611000011340 is located 0 bytes inside of 216-byte region [0x611000011340,0x611000011418)
allocated by thread T0 here:
    #0 0x7ff58fac0488 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x55dc75866f48 in std::__detail::_MakeUniq<tson::Json11>::__single_object std::make_unique<tson::Json11>() /usr/include/c++/12/bits/unique_ptr.h:1065
    #2 0x55dc758481bd in LoadTiledFromMemory /home/XXXXX/raylib-tileson/src/raylib-tileson.cpp:60
    #3 0x55dc758487d4 in LoadTiled /home/XXXXX/raylib-tileson/src/raylib-tileson.cpp:121
    #4 0x55dc758474a2 in main /home/XXXXX/raylib-tileson/example/raylib-tileson-example.c:26
    #5 0x7ff58e82350f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: new-delete-type-mismatch ../../../../src/libsanitizer/asan/asan_new_delete.cpp:164 in operator delete(void*, unsigned long)
==14721==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
==14721==ABORTING

Windows 10 platform has 4 FPS

i tried your code in 2 platforms. it correctly runs in linux with 60 fps. but when I tried your code in windows the fps downs about 4.
btw i also changed this lines because i had got an error in Windows 10 (as I said your code runs correctly in linux).
raylib-tileson.cpp line 84;
LoadTiledImage(data, baseDir, tileset.getImage(), tileset.getTransparentColor()); to
LoadTiledImage(data, baseDir, tileset.getImage().string(), tileset.getTransparentColor());

raylib-tileson.cpp line 84;
LoadTiledImage(data, baseDir, tileset.getImage(), tileset.getTransparentColor()); to
LoadTiledImage(data, baseDir, tileset.getImage().string(), tileset.getTransparentColor());

raylib-tileson.cpp line 120;
std::string image = tileset->getImage(); to
std::string image = tileset->getImage().string();

the error was;
note: in passing argument 3 of 'void LoadTiledImage(RaylibTilesonData*, const char*, const string&, tson::Colori)' [build] 33 | void LoadTiledImage(RaylibTilesonData* data, const char* baseDir, const std::string& imagepath, tson::Colori transparentColor) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.