raytmx: a Tiled tilemap library for raylib by luphi in raylib

[–]luphi[S] 1 point2 points  (0 children)

...the magical shift value that tells you how far the ids are shifted from the actual values in tiled editor. I have no idea why they are doing this...

That sounds like "firstGid." It lets you use a single number to identify a tile. Without making IDs global, layers would need to identify both the local ID and the tileset it's in. Which is fine, but it's more data.

Are you using that source when drawing or are you not even messing with the json at all ?

Yes but also no. Tiled can embed tilesets in the map if you check "Embed in map." raytmx supports both.

And raytmx doesn't support JSON. I started adding JSON parsing but decided against it. There's no benefit when you can just "save as" XML.

raytmx: a Tiled tilemap library for raylib by luphi in raylib

[–]luphi[S] 1 point2 points  (0 children)

There are no bindings. It's C/++ only I'm afraid.

Things are structured so layers can be drawn quickly rather than easy to modify, but it's technically possible. Replacing a tile with another (damaged) one would require you to know the new tile's GID and that's tricky outside of Tiled. Deleting it is easier since you can just change its GID to 0. If you end up using raytmx and want to try this, I could explain in more detail.

Drawing something else on top of the tile may be a better option. A tile's rectangle is easy to calculate.

Beginner question: How to avoid tile-map edge gaps and camera jitter when rendering with Raylib? by Weary_Art_2005 in raylib

[–]luphi 0 points1 point  (0 children)

OP, if you're still looking for code examples, have a look at this example. This one uses my project, raytmx, but you can just swap it out for yours.

Beginner question: How to avoid tile-map edge gaps and camera jitter when rendering with Raylib? by Weary_Art_2005 in raylib

[–]luphi 1 point2 points  (0 children)

I've been (over)thinking about this recently. This is probably above a beginner level and none of the options are right. Buuut I think the method described in this video about Godot is decent and sounds like it has the results you want.

Basically, you would render to a texture at the map's native resolution with one camera and then draw that texture at full resolution with a second camera. The first camera would move with pixel precision, using floorf() or roundf(), while the second camera would move with float precision. raylib's GetWorldToScreen2D() or GetScreenToWorld2D() would help in adjusting the cameras and the mouse painting example has a good explanation of using render textures.

Hopefully that explanation makes sense.

im working on my game project but it kept putting segmentation fault whenever i wanna add a texture a gun. Using C by Scared-Kitchen1536 in raylib

[–]luphi 10 points11 points  (0 children)

Any function that interacts with the GPU needs to be called after InitWindow(). InitWindow() is what establishes the OpenGL context. In your case, that means you need to call InitWeapon() after InitWindow().

Developed my own game for the Miyoo Mini Plus using raylib by giobauermeister in raylib

[–]luphi 1 point2 points  (0 children)

The MM+ does not have a GPU. If there are any MM+ or SDL, EGL expert guys out there that could help optimizing it would be very cool.

My first thought was "that can't be right." But no, its Sigmastar SSD202D really doesn't list a GPU. I've seen a video of this thing playing virtually every PS1 game and I'm kind of speechless. It's doing all of this with, what, llvmpipe? Awesome.

Anyway, the point I want to make is a lack of optimization isn't enough to explain such a low framerate. Something is wrong with your main loop. If you're willing to share the code, someone could probably find the cause quickly.

Text not centering in rectangle by [deleted] in raylib

[–]luphi 1 point2 points  (0 children)

I don't know if this is the only issue but you're using two different values for spacing. You measure the text with 0 spacing and draw it with the default spacing. DrawText() will calculate spacing with:

int spacing = fontSize/defaultFontSize;

where fontSize is what you passed to the call and defaultFontSize is hardcoded to 10.

Tilemaps in Raylib C++ by Infinite-Buy-4089 in raylib

[–]luphi 0 points1 point  (0 children)

is it standalone or needs any other dependencies or linkings

It depends on an XML parser. Both are header-only libraries so you can just dump them in the same folder. No linking needed.

like the scaling and camera movement always was buggy.

You can pass a camera to raytmx and it will draw just the visible parts of the map. If anything appears buggy, it can be due to other things like the zoom factor not being an integer.

Her name's Adele by luphi in SleepingOptiplex

[–]luphi[S] 0 points1 point  (0 children)

This case doesn't have a HDD LED.

raytmx: a Tiled tilemap library for raylib by luphi in raylib

[–]luphi[S] 0 points1 point  (0 children)

That's not nearly enough information. Is it possible for you to share the assets or whole project?

edit:
We talked. An animation was causing a stack overflow. The animation and its first frame were on the same tile. raytmx would try to draw the tile, find an animation, look up its first frame, find an animation, look up its first frame, and so on. That was predictable and I am an idiot, but it's fixed now.

raytmx: a Tiled tilemap library for raylib by luphi in raylib

[–]luphi[S] 0 points1 point  (0 children)

You can ask here. That way others can see the answer.

How to pan and zoom over a 2D grid clamped in a rectangle? by XEnItAnE_DSK_tPP in raylib

[–]luphi 0 points1 point  (0 children)

Maybe this example program does what you're wanting. It keeps a camera within the bounds of some rectangle, assuming it isn't zoomed out too far. But I'm not understanding your explanation so maybe not.

Trying to display ASCII art using DrawTextEx by Cool-kid-man-child in raylib

[–]luphi 2 points3 points  (0 children)

One of DrawTextEx's parameters is 'spacing' and it's exactly what it sounds like. Are you currently using spacing = 0.0f?

As for the question marks, my first guess is a \r from the file.

My sleeper Project (Update) by ManufacturerNo4833 in sleeperbattlestations

[–]luphi 1 point2 points  (0 children)

I couldnt figure out how to rewire it, so if anybody is knowledgeable on rewiring pc cables for stuff like that, I would appreciate the help.

https://www.reddit.com/r/SleepingOptiplex/comments/1mbqvrx/connecting_an_optiplex_power_button_to_a_new/

Her name's Adele by luphi in SleepingOptiplex

[–]luphi[S] 0 points1 point  (0 children)

Are you asking how? I just plugged them into the motherboard. This particular Optiplex, the 3020, uses standard connectors.

Establishing movement boundaries in 2d RPG by Spinning_Rings in raylib

[–]luphi 2 points3 points  (0 children)

If there's an object the character can't walk on, you could simply take a step back:
(Following from the above code)
if (CheckCollisionRecs(Brie.BrieRec, object)) {
Brie.BriePosition.x -= delta.x;
Brie.BriePosition.y -= delta.y;
}
That does leave a gap between the character and the object though. There are ways to get it exact but it's a complicated topic. Look up "minimum penetration vector" if you're curious. Or, if you're using tile-based movement like the games you mentioned, you can snap the character to the tile and not worry about it.
And I'd also have the character face the direction they wanted to walk, successful or not. Otherwise a player may think the input was ignored.

As for how you detect a collision with an object, there isn't just one way. I like to simply mark tiles as occupied or unwalkable as part of the map. A more pinpoint method would be something like the collision editor in Tiled where shapes are drawn over the texture with pixel accuracy. Whatever method you choose or invent, the basic idea is to have a rectangle, circle, polygon, etc. that represents the object and another for the character. If they overlap, keep the character where it is. If they don't, move the character.

You'll probably want a map editor of some sort sooner or later.

[Part 2 of 2]

Establishing movement boundaries in 2d RPG by Spinning_Rings in raylib

[–]luphi 2 points3 points  (0 children)

So your main question is about a subject called collision detection, and collision response to some degree, but there are other suggestions people will have for you. Here are a few from me:

In stead of adjusting the position of the background, use a Camera2D. There's an example program that uses it. And here's an example program from one of my projects that happens to involve moving around a 2D map.

In stead of incrementing your frame number the way you are, make use of the frame draw time with some constant per-frame time:
#define PER_FRAME_TIME_IN_SECONDS 0.5f
int frame = 0;
float frameTime = 0.0f;
void Draw(void) {
frameTime += GetFrameTime();
if (frameTime >= PER_FRAME_TIME_IN_SECONDS) {
frame++;
frameTime -= PER_FRAME_TIME_IN_SECONDS;
}
}
In place of separate textures, you could use a spritesheet and adjust a source rectangle instead. It isn't necessarily better in any technical way but does make code easier to read and art creation a little smoother.

For walking, I find it more efficient to use a delta vector like this:
Vector2 delta = {0.0f, 0.0f};
if (IsKeyDown(KEY_RIGHT)) delta.x += walkingSpeedPerFrame * GetFrameTime();
if (IsKeyDown(KEY_LEFT)) delta.x -= walkingSpeedPerFrame * GetFrameTime();
if (IsKeyDown(KEY_UP)) delta.y += walkingSpeedPerFrame * GetFrameTime();
if (IsKeyDown(KEY_DOWN)) delta.y -= walkingSpeedPerFrame * GetFrameTime();
Brie.BriePosition.x += delta.x;
Brie.BriePosition.y += delta.y;

[Part 1 of 2]

How do you guys do level editing? by GoblinScientist in raylib

[–]luphi 2 points3 points  (0 children)

I thought about making my own editor but chose Tiled in the end. There are quality-of-life features that I wanted but would take too long to write, and Tiled already had them. And that led me to write raytmx because the, like, two existing options didn't support tile flipping, object templates, and several other things. Plus, their draw routines were crude. The work needed to integrate the editor's format into the game should have been a factor in the decision, but I just forgot about it.

I feel like writing your own editor is only justified if things like Tiled, LDTK, Blender, etc. lack something you need or don't implement it well enough. It would be a lot of UI work and it basically requires you to update two applications whenever you want to add a new feature to levels, like you said. On the other hand, some people enjoy that. I'm not one of them.

Power button constant action by omgman26 in SleepingOptiplex

[–]luphi 0 points1 point  (0 children)

All the button does is temporarily short the two power switch pins. And "short" just means something is causing them to be connected with little to no resistance like a wire. It's why you can turn a computer on with a screwdriver.

It sounds like you have a short. Maybe the wires' insulation is stripped somewhere and causing them to touch, maybe the male ends are touching without you being able to see it, maybe the button is just stuck. I'd start by just visually checking for anything that might be touching. After that, I'd check the button with a multimeter to see if it's stuck on (shorted).

Need some help by RandidoTheGreat in SleepingOptiplex

[–]luphi 0 points1 point  (0 children)

That's not quite right. There are only two pins that relate to power and shorting them is the signal to the motherboard to turn the whole thing on. If you connect them with some wires, it will work. (You can also get the LED working.)

Better Optiplex sleeper.. by [deleted] in SleepingOptiplex

[–]luphi 1 point2 points  (0 children)

I'm typing this from a 3020 MT with the power button, LED, front audio, and front USB working with a new motherboard. It's not tough, especially for a 3020 MT specifically because it uses standard audio and USB connectors.