I have say N individual sprites. When user move them closer they snap together and become a cluster. Cluster can have sprites anywhere between 2 to n. If user touches on any cluster member sprite, entire cluster must be moved together.
Currently my problem is I can do this with lot of calculations when a move happen to organization and move them all to gather. When a new member joins the cluster I have to reorganize all again. But is there a better way to merge/groups sprites to gather? So I can perform move and rotation as a single unit. See the picture below.
The simpliest seems to be to use Scene2d Group instance to keep sprites together and a simple Scene2d Image to handle single sprite. Unfortunately you would need to rewrite your game screen but I believe that it's worth.
Here take a lok at Scene2d description and then at Scene2d tutorial
Related
Its pretty simple to transform a Point feature from one to another like this :
But I am facing a usecase that needs to animate polygon feature from one state to another, sometimes the polygons (old and new) can have different number of vertices like shown below below where I want to smoothly animate the left polygon to right?
Are there any pre-built APIs or efficient way of doing these things?
sometimes the polygons (old and new) can have different number of vertices
As a solution for this particular problem, you can simply add intermediate nodes on the polygon that has less vertices. The image below shows how to get from polygon A (a rectangle) to polygon B (a "plus" shape). It is a screenshot taken from this video, which I suggest you checkout out.
Now, the difficult part is how to determine where to add those nodes ?
Do you have more info on these polygons ? Is there a relationship between them ?
I have image sprites representing two polygons below. These polygons loosely represent the sprite area. What I want to do is use these polygons to detect the overlap (or collision) of sprites. However the overlap should be valid inside the green square. (this is a jigsaw puzzle game, what I am trying to implement is snapping of puzzle pieces when they are moved closer)
I tried Intersector.overlapConvexPolygons(adjacentPiece.polygon, currentPiece.polygon); however this one detects overlaps for entire polygon.
Any clever things I can do here to detect the overlap.
I think your approach might be over-complicating it. If you need your puzzle pieces to bump into each other, you can keep your physics boundaries, but if not, you can remove them entirely.
Either way, to detect if two pieces should snap, you can approximate each piece by a point roughly at the center of each of the piece's four basic sides. To test for pieces being close enough to snap together, you only need to measure the distance between the points on the sides of the two pieces and see if it's smaller than some threshold value you want to use.
If this is a typical puzzle game, you would only need to check this when the player releases a piece, so if it takes a while to brute-force cycle through all the potential matches, it won't really be noticeable because it isn't done while the player is dragging pieces.
If all your jigsaw pieces are a regular size you can simple use normal squares for each jigsaw piece. The square used to define the shape will be halfway between the solid part of the jigsaw piece and the extruded pieces.
From your image I have applied the squares to the pieces shown.
I am using LibGdx to develop a game. For Now I am not using scene2D. I am struck up in increasing the levels of the game as I do not have the scrolling screen.
I like to design a a scrolling screen as it is in many games which are level based (for ref, lets say Candy crush). Could you please point me a example on how to have such a scrolling screen to show a bigger area where I can show many levels.
Thanks is Advance !
Using the Scene2D function is not necessary for this and is more for GUI implementation and different screens. The Scroll pane really shines when creating reading content that does not fit your phone. I do advice to start learning Scene2D to create MenuScreens and UI though.
What Candy Crush "simply" does is having multiple backgrounds that are placed next to each other and tile seamlessly. They use buttons in the correct place for levels. By dragging a finger across the screen the camera will move in that direction. For the movement from one level to the next there is probably something like a spline in play.
It is important only to draw the background tiles and buttons that are actually visible on the screen if you have many. Since these have fixed positions and you know your camera area and position you can calculate what to draw and what not. Just drawing everything each frame is likely to slow down your fps.
You can do a search on:
Tilemaps, for you backgrounds but you probably want them in just one direction so a simple 1D array would suffice.
Dragging, to move your camera. Here I gave a basic explanations on how I do it.
Splines, are a bit tougher and you do not really need them. They could be used to animate or move something along a curve.
Thats all, expecting you know how to create something like a button (click a sprite).
I am developing a game where I want to show two objects in same layer but what is happening right now that the one which I'm writing first in render method is being shown behind the other objects.The object which I have drawn at the last in render method appears above all while rendering on screen.Please provide some code or suggestion to keep objects in same layer.For example :
batch.draw(object1,object1.x,object2.y);
batch.draw(object2,object2.x,object2.y);
As of now object 2 is being drawn above object.I want them in same layer. Object1 and Object2 are textures.
As you can see in above image,white eggs falling are appearing behind the man catching those eggs
Thank you
You will always have to render one image above another one. As you already found out, the ones that come first in your render-loop will be drawn behind the ones that come later.
If you would like to stick with rendering Textures directly, you will have to sort the drawing order somehow.
One other way is to use scene2D... Scene2D offers the Stage class, which lets you add your images to it. The same way here, the items added first will be drawn first and the others will be drawn above.
Luckily, you can change the order within scene2d quickly by changing the z-value of each item. Items with higher z-value will be drawn in front of others. This way it's way easier to reorder how you draw stuff.
As it seems in your picture, you are trying to collect eggs within the basket, so you will have to split your chicken and basket into two different images. The chicken will be drawn first (after the background of course) and then the eggs. Coming last in the draw order you need to render your basket. This way the eggs will be falling down in front of the chicken, but will be rendered behind hte basket, so it looks like they are landing into it.
Hope that helps...
I'd like to create a custom map. It should be or look like one picture, but according to the part of which the user clicks, it should move the user to a different location (i.e. start a different activity). I've seen it done in several games but I don't know how to do it myself.
The part of the picture should have non-geometrical borders (obviously it would be easily done with many square images). Sadly, I don't even know what term describes what I want to do so I wasn't able to find any helpful tutorials or discussed topics.
Example:
Picture: http://i236.photobucket.com/albums/ff40/iathen/mapEx.png
If the user touches the purple slide, (s)he should be leaded to activity_1
If the user touches the blue slide, (s)he should be leaded to activity_2
If the user touches the green slide, (s)he should be leaded to activity_3
In my experience there are 2 main (most used) ways to achieve this.
The first (my favorite):
Get the data from a PNG
You should write multiple layers to a canvas. These layers constitute your "zones" (blue, green, purple in the image). To obtain the data of these areas, you get it from PNGs (with transparencies off course) to write the canvas with whatever you want. You must store the values where there can be a tap from the user (non-transparent areas). Notice that this values can be scaled up/down depending on the map size, screen resolution, map dimensions, etc.
Once you've written the layers to the canvas you should check for a match of the user tap and the stored areas you have. You should take into consideration here the order in which the user tap is processed in your code. For instance, in your image, the purple layer is on top so it must be processed first, the blue as second, and the green as the last one. This way you can have an "island" inside a bigger area.
The second way:
Generate the boundaries programmaticaly
I think this solution is self-explanatory. The only I've faced with this variant is that when the surfaces boundaries get messy, it's really complicated to generate the proper equations.
EDIT:
Using the first approach you can employ multiple PNGs to load data or use a single PNG with data coded into the bytes (i.e. RGB values). It's up to you to decide which one to implement.
Hope it helps!
Since a touchscreen itself isn't very accurate, your collision detection for the buttons doesn't need to be either. It would be a waste of time to try to make a complicated collision detection algorithm to detect a touch within those weird shapes.
Since you are making a game, I assume you know how to handle custom touch events, as well as canvas (at least). There are many ways to do what you want, but in the specific example image you linked is kind of a special case.
You could create a giant bounding circle around the three blobs, and then check if the user touched within the bounds of the circle (ie check if the distance from the touch to the center of the circle is less than or equal to the radius). Once you determine that it is, you could check which section of the circle it falls into by splitting it up into 3 equal sections. Requires some math, but shouldn't be that complicated.
It wouldn't be a perfect solution, but it should be good enough. Although, you might have to change the buttons a little so they aren't so stretched out horizontally, otherwise a bounding circle wouldn't be ideal.
Personally, in my games I always have "nodes" that represent the visual elements of the game, such as buttons. Instead of using a large image like you are doing, I would create separate images for each button, and then check their collisions with touch events independently. That way I could have each button check with their own individual bounding circles, or, if absolutely necessary, I could even have custom algorithms for each individual button.
These aren't perfect solutions. If you do want a pixel-perfect solution, you'll need to implement some polygon collision detection algorithms
One thing to consider is screen size and ratio. The only constants you should use are for percentages.