Pathfinding nodes in libgdx - libgdx

I'm using the gdx-ai framework for pathfinding in libgdx. Is there a way to close off/temporarily remove a node in a node graph whilst pathfinding? For example, I have a character on an orthogonal tiled map where each square acts as a node and I want the character to treat the enemies like an obstacle in the node graph, moving around them rather than through them. (these enemies move and follow the player when in range)

Related

Detect coordinates within a shape

Theres 2 parts to my problem and they are related. I have a weird shape on my interface illustrated below, I am trying to randomly spawn MovieClips within its' boundaries but I am having some trouble finding a good way to do it.
Question 1: I can run an If condition to check with bitMapData.hitTest to see if the MovieClip has randomly spawn within this shape, if it doesn't simply retry with a new set of random coordinates. However, is there a better way? Like a way to only take into account coordinates within the shape? There will be plenty of MC spawned at one go so I am hoping to lessen the load, or at least find an efficient way to do this calculation.
Question 2: The MovieClips spawned within this shape will eventually have collision detection mechanics that will repel itself when interacted with. Is there a way to contain them within this shape via some kind of boundary detection?
If it was a square, we could easily have contained them with a quick check on all 4 edges, but not with this shape. Currently I am thinking of using bitMapData.hitTest again to detect for out-of-bounds after being repelled, but how do I know which Point() is the nearest 'edge' of this shape to return the MC to?
For question 1: I'm going to go on an assumption that you have some geometry data about the shape.
One method you can use to check if a point is within a shape is to take that point, then draw a line from that point to infinity (the edge of the screen) in one direction. Then count how many times that line intersects an edge of the shape. If it's odd, the point is within the shape (or on the edge) and if it's even, than that point is outside of the shape.
First link in google: https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
Or can also try a more simple method (at the cost of doing more work): if the above shape is generated with all squares and rectangles and you know the point and size of all of those: can just do a check for the point vs all the squares and rectangles that make up the shape.
For question 2: As Organis mentioned, I'd go with a library like Box2D to do this. You'll most likely spend tons of time (that you may not want to) if you try to implement this alone.
The big issue is how much cpu or gpu the code uses. You're trying to avoid using any collision detection. Collision detection is having code do calculations to determine the edges of an object. It should be the last option.
Most of the time you know there's no need for collision detection. You know where everything is and how big it is. Everything has a centerpoint and comparing simple number coordinates is the lightweight way to check if there's a need to check further.
When things get near each other, you only need to do a collision detection on the immediate area around an object. See how your shape fits in a box that is easy to check for collisions? That box should get a collision check before the actual jagged shape inside it.
Yes that collision detection box has to be drawn or mapped but it's done when the object is defined, not when the game is playing. If you are using sprite sheets, keep an xml of the boxes or circles around the shapes.

I want to collition with an attack of sword or club of enemy

I am making a 2D platform game using cocos2dx and box2d.
And I am just now making of a player collitions with an attack of enemy.
An attack of enemy is such as a sword or a club, so I want to collition when a player is contacted with an edge of sword(or club) of enemy.
So far I made of a player collitions with a bullet using box2d, but I don't know that how to make the bounding box to an edge of sword(or club) of enemy like the following picture.
How are you making like this collision?
I believe that what you want isn't a bounding box but a collection of bodies, fixtures, and shapes to make a realistic enough simulation of the enemy and player interacting with each other.
To do that, you'll need to partition the pink lined shape (the enemy and its weapons) into a set of convex polygons — just like you'd need to do for the player.
Note that mathematically speaking, any concave shape can be expressed as a combination of convex polygons. From Wikipedia's entry for Concave polygon:
It is always possible to partition a concave polygon into a set of convex polygons.
If there's few enough entities you need to deal with this for, I'd just manually do the partitioning.
For one thing, it looks like you'd need to partition things manually anyway just in order to partition the ideally immutable parts from each other. Parts like the mace (or club), the forearm, the upper arm, etc where structures like metal, wood, or bone make a part rigid enough for the detail of the simulation you want to achieve.
Then you'll need to partition these rigid parts again to match the level of detail of the simulation that you want. So the mace's head, might be represented using something close to a pentagon shaped polygon. The mace's shaft, by just a rectangular polygon. Attach those two convex shapes to a single body for the mace. And so on.
You can use algorithms (or use implementations of those algorithms) to compute the sets of convex polygons that make up concave parts if you'd prefer. Unless you're going to do this for arbitrary shapes however, I'm not sure it's worth it.

Possible to Drive Object Properties with Motion Tween?

I'm trying to create a complex parallax effect in Flash video sequence that includes translation and scaling among many layers.
I've been looking for a way to set up my scene to where I could just animate one object (preferably with motion tween) and then apply some percentage of that animation to each background object (or flip values accordingly).
Is there any way to harvest Motion Tween data out of a layer of a MovieClip and translate that into x,y values for objects? [So far I've only created instances of objects and set their positions through actionscript.]
Seems like you need to use a copy motion option of the layer context menu
Also tweening actionscript libraries e.g. TweenMax are capable of tweening any properties of any objects, but they do it with actionscript (which can be easily copied/modified/pasted), not Adobe Flash UI.
So converting every visual element to a movieclip allowed me to position the items in Z as well. That pretty much solved my problem.
Thanks everyone.

Merging two Texture Regions

In my LibGDX game I have a TextureRegion1, which I would like it to serve as a base TextureRegion. Then I have TextureRegion2, which should be placed on top of the first one.
There is the 'obvious solution' and that is to render those two TextureRegions on top of each other. But that would require more rendering time and when rendering the whole map with 10 layers on each time, the graphics processor wouldn't handle it.
So is there a way to merge two TextureRegions in LibGDX?

How can I turn an image file of a game map into boundaries in my program?

I have an image of a basic game map. Think of it as just horizontal and vertical walls which can't be crossed. How can I go from a png image of the walls to something in code easily?
The hard way is pretty straight forward... it's just if I change the image map I would like an easy way to translate that to code.
Thanks!
edit: The map is not tile-based. It's top down 2D.
I dabble in video games, and I personally would not want the hassle of checking the boundaries of pictures on the map. Wouldn't it be cleaner if these walls were objects that just happened to have an image property (or something like it)? The image would display, but the object would have well defined coordinates and a function could decide whether an object was hit every time the player moved.
I need more details.
Is your game tile based? Is it 3d?
If its tile based, you could downsample your image to the tile resolution and then do a 1:1 conversion with each pixel representing a tile.
I suggest writing a script that takes each individual pixel and determines if it represents part of a wall or not (ie black or white). Then, code your game so that walls are built from individual little block, represented by the pixels. Shouldn't be TOO hard...
If you don't need to precompute anything using the map info. You can just check in runtime logic using getPixel(x,y) like function.
Well, i can see two cases with two different "best solution" depending on where your graphic comes from:
Your graphics is tiled, and thus you can easily "recognize" a block because it's using the same graphics as other blocks and all you would have to do is a program that, when given a list of "blocking tiles" and a map can produce a "collision map" by comparing each tile with tiles in the "blocking list".
Your graphics is just some graphics (e.g. it could be a picture, or some CG graphics) and you don't expect pixels for a block to be the same as pixels from another block. You could still try to apply an "edge detection" algorithm on your picture, but my guess is then that you should rather split your picture in a BG layer and a FG layer so that the FG layer has a pre-defined color (or alpha=0) and test pixels against that color to define whether things are blocking or not.
You don't have much blocking shapes, but they are usually complex (polygons, ellipses) and would be unefficient to render using a bitmap of the world or to pack as "tile attributes". This is typically the case for point-and-click adventure games, for instance. In that case, you're probably to create path that match your boundaries with a vector drawing program and dig for a library that does polygon intersection or bezier collisions.
Good luck and have fun.