Hey! raylib forum is closing!

After a year with not much movement in the forum I decided to close it.

The cost of maintaining the hosting is a bit high for the usage of the platform, updating the forum and managing it is also a bit cumbersome and the truth is that I'm already trying to maintain multiple other networks pretty more active than this forum.

I'll recommend you to move to the other raylib networks:

- For a forum style, use Reddit: https://www.reddit.com/r/raylib/
- For direct messaging and questions, use Discord: https://discord.gg/VkzNHUE
- To report issues, use GitHub: https://github.com/raysan5/raylib

- Also, remember you can contact me personally on Twitter: https://twitter.com/raysan5 or directly by mail to ray[at]raylib.com

If you feel generous, you can also contribute to the project on my Patreon: https://www.patreon.com/raylib

Thanks to you all for joining the project and help to improve it with your questions. Keep it up! :)

Best Regards,

Ray

PD. Closing will be effective by October 31th.

Advice on Side Scrolling Using Tilemap Texture

edited January 14 in General Discussions
Hey to all, im working on the texture tilemap challenge, and i'm building my own texture tile map, and I want to add a side scroll to it. Has anyone achieved this. I have created my own tile map, my own tile map data text file. I also added a Camera 2D player in it as well. Everything is working fine, now I want to add side scroll to the left, and right. My guess is that i will somehow have to check the screensize, player coordinates, and the function below to only add tiles to the screen when appropriate.

static void DrawTilemap(Tilemap map, Texture2D tileset,Rectangle player)
{
for (int y = 0; y < map.tileCountY; y++)
{
for (int x = 0; x < map.tileCountX; x++)
{
// Somehow check to see if player or screen coordinates are within a certain viewport
// And if so only draw certain tiles to screen
if (player.x >=500) map.CountX = 20;

DrawTextureRec(tileset, tilesetRecs[map.tiles[y*map.tileCountX + x].value - 1],
(Vector2){ map.position.x + x*map.tileSize, map.position.y + y*map.tileSize }, WHITE);
}
}
}

Comments

  • edited January 14
    Here's a screenshot of whats happening when I scroll right, and the right edge of the map is no longer on screen. https://imgur.com/tNsr4fO
    Is there a way to draw the rest of my tiledata.txt file. Its only drawing the first 24 tiles , and when my player.x coordinates is a pass a certain viewport, I want to draw the rest of the 24 tiles which have not been drawn to screen yet.
  • I'd need to review a full sample carefully but why not just draw everything, no matter if it draws out of the screen?
  • Wow, simple it worked!!!. But i didn't try that because I read on a game coding forum, that its not good practice to load all tiles all at once, and only when needed, due to performance issues. But it worked with your advice. I'm learning so much from this awesome library. Thanks again Ray!
  • As long as you keep all tiles in a single texture atlas, you're just loading one texture. Don't worry for the number of tiles you draw, any actual GPU can manage several thousands with no frame-drop. :)
  • Hey Ray, is there a reason why my tilemap is drawing a black area, and not the actual tilemap bmp that was loaded. When I was working through the challenges, and I modified my own tilemap within the game, it showed the tilemap, that was being drawn. But as im creating my own game, all of my other textures are working, except for when I draw my tilemap. Here's a quick screenshot of it --> https://imgur.com/PPumDzq

    I'm actually using the same map, and function that was in the challenge to draw the tilemap.

    // Draw tilemap using provide tiles
    DrawTilemap(tilemap, texTileset);
  • Hi tshoats, what's the actual size of the tilemap? Try to keep it as power-of-two size.

    Is there any output message on that texture loading?
  • The output message i'm receiving is

    WARNING: [resources/tileset.bmp] Image fileformat not supported
    WARNING: [resources/tileset.bmp] Image could not be loaded
    WARNING: Texture format not recognized

    The size of this tilemap is the same for the one thats being used for the challenge.
    When I print the tilemap information I get the correct of x,y rows, and columns from my text file.

    Width/Height of map is 256X128

    map.tileCountX = 12;
    map.tileCountY = 8;
Sign In or Register to comment.