Show Posts
|
|
Pages: [1] 2 3 ... 13
|
|
4
|
Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] Linking a Sprite (Or another image) to a Box2D Body
|
on: 2013-05-22 07:57:01
|
Looking out for certain collisions and handling them with user data. Pushing user data into type specific working variables. This approach works for all entities of a certain class. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| world.setContactFilter(new ContactFilter() {
@Override public boolean shouldCollide(Fixture fixtureA, Fixture fixtureB) { Object userDataA = fixtureA.getBody().getUserData(); Object userDataB = fixtureB.getBody().getUserData();
Droid droid = cast(userDataA, userDataB, Droid.class); Bullet bullet = cast(userDataA, userDataB, Bullet.class); if (droid != null && bullet != null) { if (bullet.getShooter().equals(droid)) { return false; } }
return true; } }); |
1 2 3 4 5 6 7 8 9
| private <O> O cast(Object object1, Object object2, Class<O> expectedClass) { if (expectedClass.isAssignableFrom(object1.getClass())) { return (O)object1; } if (expectedClass.isAssignableFrom(object2.getClass())) { return (O)object2; } return null; } |
|
|
|
|
|
5
|
Game Development / Game Mechanics / Re: Need Help With My 2D Tile Engine
|
on: 2013-05-21 23:29:31
|
So make a separate class with a method that can check the age and determine what it should be if it returns true make a new block with the type and attributes?
Yes. Changing object behaviour with if-statements is often a sign of missing design to benefit from inheritance, object composition, polymorphism, etc. And have it in the for block, in the worldmap.render method?
No, do it before. Modifying the game world is game logic. Rendering should, well, render. Clearly assign tasks and do not mix them.
|
|
|
|
|
6
|
Game Development / Game Mechanics / Re: Need Help With My 2D Tile Engine
|
on: 2013-05-21 17:51:45
|
|
Drop those if-statements inside the block class. Instead, replace the whole block with a new object when time comes. Create some kind of watcher class which does the job. Do not inherit from Rectangle but add a property for the rectangle boundary. Probably you will get along with one block class and different color or image attributes.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: Two Questions. One About Collision of Rectangles , Other about libgdx Logic in
|
on: 2013-05-20 23:13:01
|
|
Give meaningful names to classes, methods and variables. MainCollision suggest a class that represents a collision, while it actually detects collision. A method collision() does not even suggest anything at all. What does a GameUpdate do ? Drop that garbage collector call. No upper case letters for ordinary variables. Remove unused code like the plane variable. Abstraction. If you do not need any special feature of ArrayList, use List instead. The same is true for the methods returning lists of receiving lists as parameters. Limit responsibilities. The job of a collision detector should be detecting collisions, but not taking actions on it. Just notify someone else about it.
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Re: Building a better animation infrastructure
|
on: 2013-05-16 19:02:59
|
|
Create a dedicated Animation class which holds a bunch of frames, has a current frame, knows it animation speed, gets updated frequently to switch the current frame and is able to draw itself. Just a graphics work horse. No relation to the player whatsoever.
You can develop and test that completely independent of the player and the whole game.
Let the player use that, give it a reference to one current animation object. Exchange the animation object depending on the player's state like left/right moving, attacking, etc. No images stored inside the player. When the player needs to be rendered, call the animation object to do the hard work. Use the player to hold its location and movement, hit points, inventory, etc.
|
|
|
|
|
16
|
Game Development / Game Mechanics / Re: Libgdx 2D lights
|
on: 2013-05-15 06:55:48
|
Whoa, this looks awesome, thanks!  And each flying bullet gets it own moving light as well  Kudos to Pitbuller for this little library which allows to enlighten your game without having the slightest clue about the low level details inside. Well, I guess I'm not so much looking for lighting as I am for creating an alpha mask. That seems like a more reasonable approach to what I'm doing.
I think you need to be more specific about your requirements. You have the alpha channel in color objects for instance.
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: Rectangle Intersection - LIBGDX -- Collision
|
on: 2013-05-13 06:38:13
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public class BadForLoopRemoval {
public static void main(String[] args) { List<String> items = new ArrayList<String>(); items.add("a"); items.add("b"); items.add("c"); items.add("d"); items.add("e");
for (int i = 0; i < items.size(); i++) { String item = items.get(i); System.out.println(item); if (item.equals("c")) { items.remove(i); } } } } |
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Re: Tile Maps : how do they works ?
|
on: 2013-05-04 06:33:41
|
Hello, am currently using lwjgl, but i think my question has nothing to do with it so i didn't mention that in the title anyway...
how tile maps workSCNR You recreate the whole world in each rendering pass. Set up the world once and before. What is block for int class World ? setWorld should rather be called createWorld and not draw blocks - and there is drawInWorld What is Block member drawing, why does each Block has one ? To check wrong click positions, start with the origin at 0,0, verify output, then move on slowly and see how it behaves. Instead of determining Block colors by type, set the color directly or derive sub classes with different visual appearance. Keeping modes in classes is not good and not OOP.
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Re: [Final Decision] LWJGL or LIBGDX
|
on: 2013-05-03 06:11:23
|
@StumpyStrust do i need more than glbegin/glend to do a 2D game i mean what else would i need except drawing squares,circles,line,points and loading images Developing a game is way, way more than "just" fiddling with graphics... It is about AI, game play, balancing, sound design, fun, input and usability, ui widgets and layout algorithms, network for multiplayer games, entity handling, system architecture and class design, build system, testing, storing highscores, performance optimization, difficulty tweaking, game loops, loading and saving game states, tile maps, game physics, game menus, game options, cross platform concerns, collision detection, path finding, etc. ... Not to forget polishing, polishing, polishing...
|
|
|
|
|
30
|
Discussions / Miscellaneous Topics / Re: Class size to make the most of OOP
|
on: 2013-05-02 22:07:23
|
- do not create God classes
- methods should be comprehendible at sight
- but do not split up algorithms for no reason
- clearly assign tasks and responsibilities to classes and methods, one for each class or method preferably
- look up separation of concerns
- as few dependencies as possible
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|