I'm going to build a simple online 2D game using JavaFX. but i have a question regarding animating graphic objects inside it . for example if a have a vector for "person" and want a move his hand only , Should i redraw many sprites for this movement ? and play an animation for replacing the image quickly ?
Almost I know that way . but what i want to know is there another way instead redrawing many images for one movement?
What i mean is there a way for moving the hand only freely for same image ? and If i'm using Inkscape and has exported the image as fx. does it help to do that ?
Your tips please , i'm new to this field
Use inverse kinematics for JavaFX for animating rigged vectors.
Use sprite animation for animating bitmapped images.
Use fbx for animating 3D models.
Related
I am making a game similar to Risk and struggling to find a way to implement the interaction with countries.
The basic idea is to create custom objects that are not rectangular and be able to change their colour by clicking them, highlight them with mouseover, or as the game progresses.
How would I go about having highlight-able countries that can be selected? The problem with sprites is their bounding boxes are rectangular, and if I define Box2D vertices and make polygons it gets really messy. Also, there are a lot of countries so a lot of the platformer style solutions don't fit.
How should I also change the colours of what is selected? Would it be best to have an individual sprite for every country and keep switching between them or is there a better way?
One way is to use polygons like you tried but I wonder why and what you mean it got messy. There are tools out there that let you draw vertices over a image and let you export that. You probably need to clean up the data a bit and import it into your app. It's also not very hard to make such an app yourself, have it import your image and start drawing and export to your favorite format. The more detailed you draw your polygons the more detail you get in your.
Perhaps an easier solution would be to use the opacity of each image of a country. Each country gets it's own image and you need to overlap the bounding rectangles to line them all up. When your mouse is hovering over one or more of these bounding boxes you check if the mouse is over a transparent pixel. If it is transparent you are obviously not hovering over the actual country. Some things to consider:
I would create the game in a pixel perfect manner so each pixel of your images is translated to a single pixel of the screen your outputting to.
To align your whole map I would create one big world map in your drawing application. Then save each country but remain the canvas size of the complete map. When packing these images with the LibGDX TexturePacker remove the whitespace (transparent pixels) and you will get an offset in your atlas. You can use this offset for each country to line them up and save precious texture space by removing all that whitespace.
Always check for a simple collision first before diving in deeper.
If you want to have "hover" functionality then don't do pixmap = texture.getTextureData().consumePixmap() each update since it's rather expensive. You might be better off creating your own 2D boolean array that represents the clickable area when you initialize the country object.
I am making a 2D game in JavaFX and when detecting collisions, I am getting rather inaccurate results due to the player sprite being set as the fill of a rectangle and therefore not having the intended borders. Is there a way I could make my own shape so thatI could get as accurate as possible?
Another idea I had is checking if the pixel that collided was transparent and then not ending the game if it was. Does anyone know of a way I can get the coordinates of the pixel that collides so that from there I can use PixelReader to check?
If anyone knows a better way, please let me know!
Thanks,
Ethan
There are different ways to do this. Here is one way I have used with good success. I would make hit boxes, that were themselves rectangles. Then during collision detection, I would iterate through all the hit boxes to see if they collided with the flying projectile's hit boxes.
What this allows you to do is fill in complex shapes with smaller rectangles. For example a plane would have one long horizontal rectangle and one smaller rectangle crossing at the middle.
Currently I am using libGDX. In libGDX I use their Polygon object as stated here. https://stackoverflow.com/a/28540488/1490322 I have not seen similar functionality in JavaFX, but it would not be hard to copy what libGDX is doing into JavaFX code... their code is open sourced.
I am currently working on a simple, tile based rpg for android devices. I have stumbled across an error which I cannot solve efficiently.
Rendering Mechanics
I am currently using android's Canvas implementation to render everything in my game. I load the tile map into a bitmap using an open source TMX loader I found (not really relevant which one). The TMX loader loads the map file and produces a bitmap of the data stored in the tmx file. I am using Tiled to create my maps. The game first draws this bitmap produced by the tmx loader and then all other objects (including the player) on top of the map.
The Problem
As suggested in the title, this causes problems for semi-transparent tiles such as in this map:
The gray box is where entities collide with the well in the center of the map.
This map would be rendered like this:
The arrow is the player - part of the player should be drawn under the wooden beams of the well but still over the grass
I am struggling to find a way draw the player under the wooden beams of the well and over the grass. If anyone could give me some advice on how to do this, it would be greatly appreciated.
What I have tried
In another game I was developing, I created an object layer on tiled which would contain rectangles where the map should be drawn over the player. This worked although it caused the frame rate to drop quite a lot and it is difficult to precisely plot the rectangles over the required areas.
I'm trying to make a simple java game.
I have some png file that i want to draw, but first i want to make some modification on that png. I would like to take a png, and delete to background some parts of it and add some colored lines..
For my game im using libgdx.
I dont know what to use for this, so i can search on google about it and learn.
Few hints, about what functions i should use could be awesome, Ty.
P.S. I tryed to search on internet before post here, but i didnt find something that could help me, probably idk what to search.v
Edit:
I found Pixmap from libgdx, but i can delete to background. Any advices ?
Edit2:
i want to load this texture
multiplicate when needed (no problem here)
and delete some parts of it, to background, so it will take this shape:
by using pixmap, when im drawing background over it, nothing is happen, because its draw over, not instead of.
What i could make, was using pixmap to draw the top part, that i want to delete, and manualy delete it using external programs:
I think you might want to look at a "mask" image. There are some approaches listed here: https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Masking
Alternatively, you could use create a mesh that encodes the "ground" (with the bump) and then texture it. OpenGL would take care of truncating the edge of the mesh. Try: Drawing textured polygons with libgdx
Another approach is to just draw the dirt texture on the full screen, and then draw the "background" over it. You will need to make pixels in the "background" image transparent so the dirt will show through. Whatever pixel editor you are using should be able to do that. Alternatively, pick a "key" color and convert those pixels to transparent when you load the image as a pixmap.
I don't know if this question is serious, but you cannot do what you're asking in Java. You need a photo editing software such as Photoshop or GIMP.
I'm making a game in Java and I have it so that when the player presses the left arrow button, three images are drawn one after the other. But when the third image is drawn, you can still see the image drawn before it (I rotated the images to make it look more realistic). Is there anyway to "undraw" the images? I've done some research and haven't found anything specific.
No, you can't undraw an image. It sounds like the images aren't fully opaque.
Not to be an over-complication junkie, but how about using OpenGL to draw them on quads. That way you can hide, show, rotate, animate, accelerate etc so much easier. And it will all be tons faster than with Swing/AWT. JOGL library + NeHe Tutorials will quickly show you how to achieve this (really, you only need this and this). Or use Unity if you wanna do it even simpler and more portable.