So I'm creating a 2D game platform that works with Tiles. Currently it won't let the player go through the any tiles and works fine. Though rather then stopping the player at a solid tile. I would like to stop the player at an actual object. Pretend the triangle is in a tile.
Whats Happening:
What I want:
I would like the player to be able to walk through the tile until their is no more transparents. Basically walk on the triangle.
Player Class http://pastebin.com/SJrzSvVV
Tile Class http://pastebin.com/V3nqxh61]
TileMap Class http://pastebin.com/fuj8dR5K
You should check out the intersects() method provided by the Java2D API.
You can define the two sprites as shapes and adjust the coordinates when the two shapes intersect. I'm guessing you are splitting up a BufferedImage to create the animation frames.
You can draw a Rectangle or Ellipse frame around your sprites and check those for collisions. The frames do not have to be visible but making them visible helps when debugging.
Figured it out, essentially what I did was I was creating this game using tiles. I created something to scan a tile and find out where it's transparent, and allow players to go through it or not depending on whether the transparency is already inside something in the tile or not.
Related
I have an image with walls in it for my little maze game but currently, my player can move around freely meaning on top of the walls. If I want to restrict this free movement with walls, do I have to paint multiple rectangles one by one and align them properly so that they match the walls in my image, and if my player is hitting a certain wall, I would have to make a collision detection check? Or would I need to make a Wall class and create wall objects with methods which can check if they are in contact with the player, can restrict the movement? How would I go on about achieving this?
I've made a few 2D games using JPanels and the Graphics draw methods. For the game I'm currently working on, I'd like to be able track the player as they walk, from an aerial view (sort of like the earlier Pokemon games, where as you move the camera tracks you), but without having to hard code it (make it that when I walk, the x and y values of every other feature including the background moves the opposite direction). Is there another way to do this or will I have to hard code it?
Use Graphics.translate(x,y) where x and y positions are the positions of your camera or player. This will translate the origin of the graphics context to the point x, y.
Let's say I have a triangular face in 3d space, and I have the 3d coordinates of each vertex of this triangle, and would also have other information about the triangle(angles, lengths of sides, etc.). In Java, if I have the viewing screen and its information, how can I draw that plane, without using libraries like LWJGL, to that image, assuming I can properly project, accounting for perspective, any 3d point to that 2d image.
Would the best course of action just be to run a loop that draws each point on the plain to a point on the image(i.e. setting the corresponding pixel), which will most likely set the same pixel multiple times? If I'd do this, what would be the best way to identify each point in an oblique triangle, or a triangle that doesn't line up nicely with the axes?
tl;dr: I have a triangular face in 3d space, a "camera" looking at the face, and an image in which I can set each pixel. Using no GL libraries, what's the best way to project and draw that face onto the image?
Projection :
won't detail as you seems to know it
Drawing a line
you can look at Bresenham algorithm if you wanna start with the basics
(hardwared in recent graphics card)
Filling
you can fill between left and right borders of the triangle while you use Bresenham on both (you could use a floodfill algorithm starting ... i don't know, maybe at the projection of the center of the triangle)
Your best bet is to check out the g.fillPolygon() function for Java. It allows you to draw polygons with as many sides as possible and theres also g.drawPolygon() if you don't want it solid. Then you can just do some simple maths for the points. Such as each point is basically it's x and y except if the polygon is further away the points move closer to the center of the polygon and if the polygon is closer they move further away from the center of the polygon.
A second idea could be using some sort of array to store pixels and then researching line drawing algorithms and drawing lines then putting all the line data in another array and using some sort of flood-fill. Then whilst it's in that array you could try and do some weird stuff to the pixels if you wanted textures or something.
I wanted to ask if you can use box2d lights so you can see only objects that are in the lights area. For example i have a flashlight and only want to see game objects in the light. I managed to do something like this but the problem is that the sprites of the game objects lose their color intensity because I render lights on top of sprites and the game itself doesn't look good because of this (even though it is the effect that i want).I used box2d bodies with user data containing sprites. I can't figure any way out. Is there any proper way to use box2d lights library to make these objects visible and with their real color? (I am setting lights to X-rays to do this; also I am using it with libgdx in java).
It may be because the default setting is to not use diffuseLight. You have to set rayHandler.useDiffuseLight(true).
Libgdx and Box2DLights - too bright + colors grayed out
I have a sprite which is ball. Let's say, it represents a glass ball.
I am rendering the graphics with SpriteBatch.
Is it possible in libgdx to have a breaking glass effect for the ball? Meaning, I want to split the sprite to different pieces with abnormal borders (not rectangular) and then draw them flying to different directions.
Use a PolygonSprite to represent the non-rectangular chunks of your sprite.
To generate the chunks, I suggest picking a random spot near the center of your sprite, and then creating several triangles from that point to the corners and 2 or 3 points on each side of the square sprite. You should be able to define a PolygonRegion for each shard, and use that to build PolygonSprite instances.
I haven't actually used the PolygonRegion API before (and it looks a bit obtuse), so you might want to check the examples.