Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 4
1  Discussions / Miscellaneous Topics / Re: Advice on dealing with internet trolls? on: 2014-03-25 16:53:29
Stay calm. If a person tries to annoy you, the best way to annoy them is to stay calm. If you get angry, they are amused, because a) they achieved their goals, b) it's fun to see a guy being annoyed.
Of course time to time I lose my patience with them, but the good thing about being behind a keyboard is that, you can take your words back.
2  Game Development / Game Play & Game Design / Re: Start, Pause and Game Over screens on: 2014-03-24 20:15:15
Well, I'll try to implement something for this, but let's see how it goes.

I'm not looking for a perfect or professional or right way to do these screens, so it's okay atombrot. I'll download the source, compile it and see how you did that.

But still I'm open to alternative implementations if anyone does this in some other way.
3  Game Development / Game Play & Game Design / Re: Start, Pause and Game Over screens on: 2014-03-23 19:34:12
Thanks for the replies guys.
So, you have another screen for these stuff and you just take the player to that screen when the game stops or it's over.

I wonder, doesn't that affect the gameplay? For instance, my game turned out to be an infinite jumper now (lol). So, that means if the player falls, the game should be over. And that means, the player should be able to see what's going to happen when the game begins so that he can have time to react (for example, press "left" key to prevent the player from falling down and the game from an instant end. Ugh... I mean, if I have a Pause screen, the player won't be able to see what's next.

Another concern for me would be preserving the game state, which I have never tried to do. The whole idea of pausing the game is to be able to start from the exact spot you left. I don't know how to do that. Any guides for this?  

EDIT:
@atombrot
I'll have to get the whole project and play with it, compile it etc. I hope that is okay for you. Of course I'm not gonna distribute it. I won't use the code, but I might take inspiration from it, as the whole point of me looking at that code is to learn how you guys do it Smiley
4  Game Development / Game Play & Game Design / Start, Pause and Game Over screens on: 2014-03-21 22:20:15
I am trying to make a platform game using Box2D and LibGDX. I wonder how you handle Pause, Start and Game Over screens.

By Start screen, I mean this: When the game begins, I start it as paused, so the player can be ready for moving the character. I do this by rendering a black image with alpha= 0.5f, and a Scene2D label "Touch the screen to begin".
I don't have a Pause screen yet lol.
Game Over screen is also a black image with 0.5 alpha value and a label saying "Game Over". I haven't put any buttons for restart or go to menu, but I am planning to do.

But like I said, I wonder how you handle these kind of screens. Do you make a new class which extends Screen (those who are familiar with LibGDX should understand what I mean Smiley) and show that when the player pauses the game or when the game is over?

What do you do with these screens? How do you handle this?
5  Game Development / Newbie & Debugging Questions / Re: Abort trap error with LibGDX and Box2D on: 2014-03-19 20:33:05
Now, I think I fixed it. But I am not sure how.
I checked my Entity class and its subclasses. The hierarchy and the relations between them were so messed up that I couldn't tell where a variable was actually got a value. Fixed those. Got the error.
Then, I tried to simplify my Entity.init() method. Some of the code in that method belonged to the constructor. Did some trial and error, fixed those. And I haven't got that error since. That makes 1 hour of playing that boring game. It should be okay.

At least that's what I was thinking. It gave another error the last time I closed the game, the error was just after the shut down. And it is a different one this time. It happened once and it doesn't say anything about my code, but it happened outside of JVM, in native code again.

Here: http://www.java-gaming.org/?action=pastebin&id=869

I'm not sure if my code can cause that. By the way, if I get my old error, I'll head here again Smiley
6  Game Development / Newbie & Debugging Questions / Re: Abort trap error with LibGDX and Box2D on: 2014-03-18 22:49:54
I was suspecting it has something to do with how I destroy bodies from the world, but the error log says something about creating one (I guess).

Stars are floating, here:
https://www.dropbox.com/s/e40juifo7cgriy7/Screenshot%202014-03-18%2023.46.35.png (Seems like JGO doesn't like Dropbox).

This is my process for platform and star creating: A platform is randomly created with a fixed width and height, the x and y location are randomly defined. Then the platform is put into the world. Then, as you can see in my test(Platform p) method, I take the x coordinate of the platform and make it star's x, and take the y coordinate of the platform, and add 1 to it so that they don't overlap, then set this as y of the star.
So, if a platform is located at 10, 12, then the star is at 10, 13.

Meanwhile, stars and platforms are kinematic bodies, they do not move and their location isn't changed neither in my code by the user nor by any collision.
7  Discussions / General Discussions / Re: Good idea to jump around project? on: 2014-03-18 22:35:20
I think as long as the side project is not as big as the main one, or nearly big as the main one, it is good to do so. I think it provides a good 'distraction'.
I don't have enough time to have more than one programming projects, but I have other things. School, translation, music, programming... I have options, so I can use my time by doing something useful. But none of these should be as important as the school, or else I fail at that.
Needless to say, my progress with anything else than school is slow. Side projects are bound to progress slower. If you think you can live with unfinished projects around you for a while, you may start more than one projects.
But I think if you had more than one project in your hands (like, you have two schools you should go, or two games to develop), since these are similar stuff, and in case of programming thing, they are both in your computer, in your favorite IDE, it's likely that you just switch to the second project when you have a tough obstacle in the other, and stay on that one until you have a similar thing in the second project.
8  Game Development / Newbie & Debugging Questions / Re: Abort trap error with LibGDX and Box2D on: 2014-03-18 19:11:11
@Grunnt,
I already do what pitbuller suggested as possible solutions, but I double checked what he said, thinking maybe I think I did them didn't actually do them. I double checked them Smiley Problem still exists.
The most annoying thing is that, it seems it's completely random.

@Gibbo3771
Thanks. Right now, I'm doing as you said with logic>input>render. I also check whether the world is locked or not.

But I'm not checking if my body is null or not. In my initializing methods, I create the body first, then add a sprite to it. So I was thinking it's not really necessary, because I create the body, put the sprite, and that method only called once. But I'll try your suggestion for a more secure code (secure for me).

I have a hunch that this is about removing bodies but it worked well before...
-----
While I was writing this answer, I got distracted and read the error code again. Check this out:
Quote
j  com.mesut.jumper.utilities.Randomizer.test(Lcom/mesut/jumper/entities/Platform;)V+41
This is the method I am putting a star (to be collected) just one meter above the platform.
Here is my platform generating method and that test method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void generatePlatforms() {
float minGap = 3, maxGap = 5.5f;
float realGap = MathUtils.round(MathUtils.random(minGap, maxGap));
edge = getEdge();
float realWidth;
if (edge - gameScreen.getCamera().viewportHeight / 2 < gameScreen.getPlayer().body.getPosition().y) {
float platformY = edge;
realWidth = 2f * gameScreen.getReferencePlatform().texture.getWidth() * WTB;
bodyCenter = MathUtils.round(MathUtils.random(gameScreen.getScreenEdges().x + realWidth, gameScreen.getScreenEdges().y - realWidth));
Platform platform = new Platform(gameScreen.getSpriteBatch(), gameScreen.getWorld(), WTB, bodyCenter - realWidth / 2, bodyCenter + realWidth / 2, platformY + realGap);
gameScreen.getPlatforms().add(platform);
test(platform);
}
}

public void test(Platform p) {
Vector2 collectiblePoint = new Vector2(p.getX1(), p.getY() + 1f);
Coin c = new Coin(gameScreen.getSpriteBatch(), gameScreen.getWorld(), WTB, collectiblePoint);
gameScreen.getCollectibles().add(c);
//Coin class extends a class called Collectible. Collectibles is an array which holds collectibles to render.
}


Now, let's take a look at the first lines of the error:
Quote
C  [libgdx.dylib+0xa978]  b2BlockAllocator::Allocate(int)+0x58
C  [libgdx.dylib+0x1fd96]  b2World::CreateBody(b2BodyDef const*)+0x26
C  [libgdx.dylib+0x27d4e]  Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+0x9e

It seems to me that this is not about destroying the bodies or objects, but it's about creating them. Right? If so, there must be something about the test(Platform p) method (I can't remember why it's called test).
Is it not a good idea to create a body using other body's information? Maybe that is where I should put the if statement Gibbo talks about? Well I'm gonna try that and see if that's the reason.

I'm still open to any kinds of advice Smiley It's nice to see other people's ideas about this.
9  Game Development / Newbie & Debugging Questions / Re: Abort trap error with LibGDX and Box2D on: 2014-03-17 20:18:16
@pitbuller,
I know it's the common mistake. The other is to try to remove a body while the world is still locked. I experienced them both, and I solved them both. This is not one of them. But thanks for help Smiley

@princec,
I think libgdx has some methods to manually allocate memory. I'm now allowing it to handle this for me, because I am not sure about the amount to be allocated. But I hope I can solve this without having to take a look at the source code of LibGDX.
10  Game Development / Newbie & Debugging Questions / Re: Abort trap error with LibGDX and Box2D on: 2014-03-17 18:58:11
Thanks TeamworkGuy2.

My project doesn't seem messy to me maybe just because I am the one who wrote it all, but I think it is messy, because I'm experimenting on the code.

I appreciate you took a look at the crash in the pastebin. I was planning to improve the game a little bit more, change the graphics from the ones I found on the internet which I don't know the source to the ones that I could give credits for. But now I'm going to tidy up the code a little, and then put it to WIP section of the forum and try to work this error out.

Of course I'll take your advise, and start from there. The main reason I asked for help is not the error itself, but the randomness of the error. I think I might have to rebuild that class. And the subclasses, because I have lots of classes which extend that one.


Native code is Box2D as you (and all others who read it) can guess if you know about it. I used to be able to fix those ones (Last one was an easy one, removing a body from the world, but keeping it for the update and render). But they generally gave me more obvious code locations.

I am keeping looking into it, but I won't say no to any help offers in the mean time. Actually, I'd appreciate it. Any pointers, any hints, or anything I can help you to help me... I need anything I can get from you people.
11  Game Development / Newbie & Debugging Questions / Abort trap error with LibGDX and Box2D on: 2014-03-17 15:17:40
I'm trying to build a game with LibGDX and Box2D.
In the game, I have stars to be collected and platforms to jump on. The starts are removed from the Box2D world when the player 'gets' them. They also removed from the world if they are not visible in the screen anymore. Platforms are removed from the world.

This is the first time I am getting an error like this (Well tons of times for this project, but never on anything else). It is totally random. I can't pinpoint any lines or methods. I tried this on Eclipse, exported Jar file and on Android. Sometimes you can play the game for like forever, but sometimes it crashes in 1 minute.

There are no particular action to trigger it. My game is only about jumping and getting the coins, and these two are the only things you can do. On Eclipse, sometimes it just freezes, it doesn't crash but it also does not do anything. But most of the times it gives this error.

Here is the error I am getting:
Quote
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000110886978, pid=3221, tid=62211
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libgdx.dylib+0xa978]  _ZN16b2BlockAllocator8AllocateEi+0x58
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/mesut/hs_err_pid3221.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Abort trap: 6

This the error report file at /Users/mesut: http://pastebin.java-gaming.org/0c1e98e648f

I know I'm not giving much detail, but if there is something I can do, please tell me. I have a messy project, but I can upload it to somewhere if that makes a difference.

Can you tell me what this means? Or the ways to overcome it? Thanks in advance Smiley
12  Game Development / Newbie & Debugging Questions / Re: Does using a library still expand one's abilities in general game-development? on: 2014-03-15 23:30:32
As a person who knows Java and took a step to LibGDX, I can say most of the stuff actually relies on your Java knowledge, not your library knowledge.
To be honest, there are lots of ready-to-use codes for certain tasks. For instance, if you look for "the most efficient way to render in Java", you'll find some pages. Same goes for any other concepts like collision detection, path finding, score keeping etc.
Don't take anyone's word for it, go look for these codes. You'll see that the codes are more or less library independent.
There are some libraries that removes the need to learn some concepts, though. For instance, people like me who use Box2D for all the physics won't know the logic behind how a character's direction is decided after the collision.
But I imagine you're just talking about libraries like Libgdx, Slick2D or similar stuff.

I have to tell you, it is inevitable for anyone to look at the source code of the library he's using. And that's because of the mistakes he's going to make and the errors he's going to get. I don't know any C/C++ but because of the errors I get, I feel the need to take a look at the source code of Box2D which is written in C/C++.
If you are curious and the library you are using is open source, you still have the chance to learn the deepest stuff.

It is told you many times in this thread that game development skills are independent from library knowledge. I'll let you hear it from a person who is nothing more than a beginner; These two are different things. Just imagine the pseudo-code and the actual code  of the game you're trying to build. You'll find out that it's more logic than rendering the graphics. And, the logic is not handled by any of the libraries. It's still you who have to move the player, shoot the bullet, make the enemy attack and make the platform move.

But for a while, you'll have to stop learning game development to learn the library. This is interestingly a short time. Because you have to practice what you've learnt, and the only way to do this is to try something.

I repeat, game development is more about logic than the other things, so most of the stuff you learn will stay with you if you switch to another library. To be honest, I think libraries make it easy for you to learn the game development logic.
13  Discussions / General Discussions / Re: What things should I learn? on: 2014-03-05 20:15:08
I'm a newbie as well, but I'll state my view because I can.

When I first started to game developing thing (been a while), I tried simple stuff first (not a simple game). After I managed to render two sprites and make them move around, I thought I'm good enough for a game which includes AI.
I was not.
Not being able to move on with my project, I lost interest to development. Also life got in the way, but mostly I lost my interest. But it taught me one thing, and it taught me well: I had to start very simple.
Because what you imagine in your mind may not apply to the code.
But to learn that I had to start simple, I had to try something. Reading is good, but it won't get you much. Because you think you know the theory, and maybe you know the theory. But the practice is different. Practice is the thing differs doctors from wikipedia pages. It's that important.
You don't have to start as simple as I am doing now, but find an idea and try to implement that. If you can't, start with something two steps lower. Then build your way up.

I think making clones at first is not bad. At the moment, I'm making a very simple infinite jumper game. It is primitive. It probably will stay like this. But I also had a list with it, the list of things I couldn't do. For instance, I couldn't keep my character in screen, it just fell. But I fixed it, so I can check this off. I couldn't spawn the platforms randomly. Now I can check that item off from my list. Now I can't spawn collectible items randomly in a way that they don't overlap with the platforms. I'll be working on that when I have time.

I'm not a fan of video tutorials. Although some of them are good and explaining stuff, inevitably, and that's not the author's fault, it becomes a "I make the game, you guys watch me coding." thing. And you may be stuck with their wrong implementations if they are not doing it right. And let's be honest, you can't expect them to teach you everything for free. You may learn one thing from them, but not the whole concept of game development.

One tip about the tutorials, and I am not giving this tip as a programming and game developing enthusiast, I'm giving tip as a student who learnt that the hard way, as a learner who suffered from it in different areas: DO NOT COPY AND PASTE from the tutorials. Get the idea first. Try to think why he did it like that. If you can't, it's still good. Then just type. You may realize the reason behind it while you are typing. Change the names of the variables to your liking. Add your own comment lines to the code you are typing. Even if your comments are wrong, you'll come back and find out the correct ones. Type them instead when that happens. Change the values of the variables. Treat that code as your homework, like, you know you are supposed to do it like your teacher told you to do, but you feel like it would be cheating to just look at the example and write it down, so you try to do it your way.
Well I'm just trying to say, use your head, not theirs.

If programming is not your career choice but a hobby, treat it as one. It'll be more fun that way. Don't let the professionals (or computer science students who naturally know more than you do) make you feel down. They don't mean to do that (at least I hope Tongue).

And please, please be a good friend of yourself and don't try to do everything right in the first time. Most of the professional programmers who I talked to told me that they look at the code they wrote 1 year ago and realize how stupid they were and how they could have make their jobs easier. I think that would be more satisfying than finishing a couple of projects. -- That's how they know they improved.
14  Discussions / Miscellaneous Topics / Re: WIP games, tools & toy projects forum on: 2014-03-04 17:16:07
Thanks guys. Once I have something visually not bad, I'll put it here.
15  Discussions / Miscellaneous Topics / WIP games, tools & toy projects forum on: 2014-03-03 20:23:20
I'm not new at Java or Java game development, but I am a novice at game development, I don't have much time to code/learn. And the time I have is not regular (I can't say 1 hour/day, but I had 10 hours in a day, then nothing for days etc.) But I still want to do something.

I switched from reading stuff to trying to do stuff, and now I can really do something. I have a project which is an infinite jumper, I intend to finish it and polish it as much as I can. Because I think that is the only way I can learn new stuff (although the process will be similar from now on) and learn how to debug and improve my code etc. I mean I won't leave this project (but may start additional ones Smiley) after I prove to myself that I can make a player jump on a platform.

However, knowing myself, I think my focus will be lost in time. So I'm thinking of getting my project into WIP games. It's not ready yet, it has no real graphics, it has amateur codes, it has everything that is not good. Also it doesn't have any original ideas, doesn't have a story, a name, it does not have most of the good stuff. But I am proud of myself about learning new stuff while trying to make it work.

I think the only way I can get critics (which will be harsh mostly, probably) is that I put my project here and share the code with you. Maybe then, when you have tons of time to waste, you take a look at my code and point out what I do wrong, what I could do instead. Then maybe one day, it will be good enough to release it for real. I take criticism well and usually respond to it by fixing my mistake.

I can hear you guys saying "That's kinda the point in WIP forum", but what I'm afraid of is that, I may not have time to do more. It's not impossible to get your head around some tough concepts thanks to helpful people from all over the Internet, what makes me think is if I can have time to do it.

I'm not intending to be the next 'indie king' or have the luck&success of the Flappy Bird developer. I just want to have one more hobby, and I want to be able to show something that is the result of this hobby, game coding.

So, what do you guys say? Should I put my game and code here? Note that it is now just a box jumping on other boxes now, and the circumstances are a little weird - I can make a breakthrough everyday, or you may not hear from me for weeks etc.

16  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX - Box2D] Deleting bodies on: 2014-03-02 20:37:38
It was so simple. It was so simple that nobody ever had the same issue on the internet.
It was so simple that I feel stupid because I didn't think it before.

So, I have an array there, right? That's called delete. When the collision occurs, I have one element in the array. When the world is not locked, that is, the world is not stepping, I remove the body from the world. But not from the damn array.

This code always looked a little bit simple to me:
1  
2  
3  
4  
5  
6  
7  
Iterator<Body> i = delete.iterator();
if(!world.isLocked()){
   while(i.hasNext()){
      Body b = i.next();
      world.destroyBody(b);
   }
}


Add this, and it is done:
1  
i.remove();


Code is not important, just delete the object as well.

I'm not sure if I ever come across to a situation where this is problematic, but at least I should have thought that I needed to remove the object from the array as well. It would try to destroy a null 'thing' from the world again once the world is not locked.

Damn...

Damn 5 hours and I did nothing. I could be having a drink, I could be reading something useful, I could be meditating but no... That problem had to be stuck in my head. And that small damn idea had a business in somewhere else, that it didn't bother to check if it is needed in my head.

Man I'm furious right now.
17  Java Game APIs & Engines / Engines, Libraries and Tools / [LibGDX - Box2D] Deleting bodies on: 2014-03-02 15:03:58
Hi,
So I want to delete some bodies after they collide.
I have a Contact class which is a ContactListener class. In the postsolve method,
screen is my game screen, and delete is an array of bodies which I'm trying to remove:
1  
2  
3  
if(contact.getFixtureA().getBody().getUserData().equals("player")&&contact.getFixtureB().getBody().getUserData().equals("gold")){
   screen.delete.add(contact.getFixtureB().getBody());
}

Then I'm deleting my bodies like this:
1  
2  
3  
4  
5  
6  
7  
Iterator<Body> i = delete.iterator();
if(!world.isLocked()){
   while(i.hasNext()){
      Body b = i.next();
      world.destroyBody(b);
   }
}

But it gives me an error: Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file ./Box2D/Dynamics/b2Island.h, line 54.
I run this code just after I set the world to step.
Step is like this: world.step(1/60f, 6, 4);
Played with the numbers, didn't help.
I also have a randomGenerate() method which generates a platform, and adds it to the world. I thought that could be the reason because the error includes the word "Add" Cheesy But the problem persisted after I removed that method, meaning I only had two bodies in the world.


I also tried setting world step to 0, adding b.setAwake(false) and b.setActive(false) but nothing changed. The problem is always the same:
Quote
Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file ./Box2D/Dynamics/b2Island.h, line 54.

Now, I have no C/C++ experience but here is the 54th line:
1  
2  
3  
4  
5  
6  
7  
void Add(b2Body* body) <-- 54th line. 
{
   b2Assert(m_bodyCount < m_bodyCapacity);
   body->m_islandIndex = m_bodyCount;
   m_bodies[m_bodyCount] = body;
   ++m_bodyCount;
}


Please note that this happens even when there are only two bodies in the screen and nothing else is going on.

What can I do?
18  Game Development / Newbie & Debugging Questions / Re: Hard to start a project. on: 2014-03-02 13:09:30
My projects generally suffer from my lack of knowledge, but never on graphics or audio.

I just collect some stuff from the internet, and use them. Because I'm not going to release any games soon. And the graphics don't even need to be cute or in harmony. I always cut a part of any wallpaper in my computer and put it as my sprite. Now my sprite is a wallpaper from a "fire wallpaper", so it's just a part of a fire. I mean, I use placeholders. At the moment I have this:

Looks bad, doesn't make sense etc. But my game doesn't make sense as well. Also it's not even near anything playable.

But if you can come up with something publishable (is that a word?) and stuck with graphics like mine (a 16x16 pixel piece of a random wallpaper), just search the internet for sprites etc. Most of the times, all you need is to ask artist's permission, because again, most of the time what an artist wants is to show his work to the world. Some of them wants you to have something. I mean, something you can show to them, "That's where your graphics will be". I have a friend who told me to come to him after I am done with most of the code. He wants something he can play on his phone before spending time on the graphics.

And there are some people who just releases their graphics etc for free use after their game is published.

In case you go with graphics from all over the web, keep their link somewhere, so if you decide to publish your work with their graphics, you can ask their permissions.

All my point is that, in my opinion, graphics have a little importance while you are coding. Their real importance comes to light when you want to show off your game.
19  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Box2D and LibGDX coordinate system issues on: 2014-02-24 20:40:41
I posted this on badlogicgames forum as well. I thought it's only fair that you should know about this. I'll keep you updated if there is a new answer there which solves my problem.
Here is the link: http://badlogicgames.com/forum/viewtopic.php?f=11&t=12961

People over there gave me some suggestions, which I am already using. And BurningHand gave me idea that I should post my whole post to help you help me better. So, I modified the first post in this topic.

I also have a video to explain what my problem is: http://videobam.com/SFfHI
English is not my native language, so maybe I couldn't explain it. The video probably will tell more than words here.

Also, I'm still in need of help with this Smiley
20  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Box2D and LibGDX coordinate system issues on: 2014-02-22 22:18:15
Check the link for my problem, I think it tells more than words: https://www.dropbox.com/s/v52aad27hbw0j4h/Screenshot%202014-02-22%2023.22.57.png
21  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Box2D and LibGDX coordinate system issues on: 2014-02-22 22:01:10
Body is a static one, so it will stay wherever it is created. That's why I typed them in the constructor.

Also, what you suggest has the same problem, the gap gets bigger as the coordinates get bigger. I know that, because I tried that. I tried again, with Here is a screenshot with this code (Coordinates are: x:0, y:200, x2:300, using this constructor: shape.setAsBox(hx, hy, center, angle);:
1  
2  
3  
sprite.setOrigin(body.getPosition().x, body.getPosition().y);
sprite.setPosition(body.getPosition().x - sprite.getWidth()*WTB/2, body.getPosition().y - sprite.getHeight()*WTB/2);
sprite.setRotation(body.getAngle() * MathUtils.radDeg);



Image doesn't show up on my computer so: https://www.dropbox.com/s/vxxbw2tacmby3do/screen.png

But the main problem is not their positions, my first image is in the bottom of the screen and body and the sprite fit perfect. But another body on the top of the screen which is created using the exact same class and method, has its body and sprite in completely different places.
22  Game Development / Newbie & Debugging Questions / [LibGDX] Box2D and LibGDX coordinate system issues on: 2014-02-22 20:54:42
It seems that Box2D coordinate origin is the center of the screen, and LibGDX coordinate origin is the top left side of the screen. This causes problems when I try to draw a sprite on a Body.

This is how I create a body and draw a sprite:
EDIT: I POSTED THE WHOLE CLASS BELOW, ORIGINALLY I JUST PASTED THE CONSTRUCTOR.
width is an array which has 3 elements, these are x1, y and x2 for creating the shape. I'm using y as y1 and y2.
Drawing is simple enough, just sprite.draw(spriteBatch);

As you can see, I'm keeping a log of the body position and sprite position. Both the bodies and sprites are rendered using the same camera. My scaling is correct, my bodies and sprites are in the same size.

The weird thing is that, body position and sprite position are same, but they are not the same in the screen. There is a GROWING gap between sprite and body.
For example, if I render a body and a sprite on width[]{1, 5, 7}, it is fine. The body and the sprite are in the same position. But if I render on width[]{1,100,7}, the gap is about 10 cm.

What do I do to fix this?

EDIT: I POSTED THIS ON BAD LOGIC GAMES FORUM AS WELL. THE SUGGESTION WAS THAT I PASTE MY WHOLE CODE HERE. SO THAT'S WHAT I'M GOING TO DO:
This is my GameScreen class, which can be considered as a world that renders and updates everything:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
public class GameScreen implements Screen {

   // 2x32 image is 1x1 meter
  public final float WTB = 1 / 32f;

   private OrthographicCamera camera;
   private Box2DDebugRenderer renderer;
   private World world;

   // Bottom. I'm putting a static body at the bottom of the screen so the player doesn't fall
  private ChainShape borderShape;
   private FixtureDef borderFixture;
   private BodyDef borderBody;
   private Body ground;
   //These two will be used for my randomization process, which I haven't done yet.
  private Vector2 bottomLeft, bottomRight;

   
   private SpriteBatch spriteBatch;
   Player player; //This is just a dynamic body with a sprite attached to it.
  //After I realized the problem, I needed more than one platforms, so I made an array for them.
  private Array<Platform> testPlatforms = new Array<Platform>();


   @Override
   public void render(float delta) {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      renderer.render(world, camera.combined);

      spriteBatch.begin();
      player.render(); //Player works perfectly.
     // Whether I iterate or render them seperately, the result is the same
     Iterator<Platform> iterate = testPlatforms.iterator();
      while (iterate.hasNext()) {
         Platform p = iterate.next();
         p.render();
      }
      spriteBatch.end();

      //Normally the rest is in another method called update(), but I just combined them here.
     world.step(1 / 60f, 1,1);
      // Follow the player - I removed this, it didn't change anything.
     camera.unproject(new Vector3(player.body.getPosition().x, player.body.getPosition().y, 0));
      camera.position.y = player.body.getPosition().y;
      // Limit the movement
     if (player.body.getPosition().x > bottomRight.x) {
         player.body.setLinearVelocity(player.body.getLinearVelocity().x* (-0.75f), player.body.getLinearVelocity().y);
         player.body.setTransform(player.body.getPosition().sub(2 * WTB, 0),player.body.getAngle());      
      } else if (player.body.getPosition().x < bottomLeft.x) {
         player.body.setLinearVelocity(player.body.getLinearVelocity().x * (-0.75f), player.body.getLinearVelocity().y);
         player.body.setTransform(player.body.getPosition().add(2 * WTB, 0),player.body.getAngle());
      }
      camera.update(true);
      player.update();
      spriteBatch.setProjectionMatrix(camera.combined);
   }

   @Override
   public void resize(int width, int height) {
      //It still shows in meters.
     camera.viewportWidth = width * WTB;
      camera.viewportHeight = height * WTB;
      camera.update(true);
   }

   @Override
   public void show() {
      // Camera shows in meters now, not in pixels.
     camera = new OrthographicCamera(Gdx.graphics.getWidth() * WTB,
            Gdx.graphics.getHeight() * WTB);

      renderer = new Box2DDebugRenderer();
      world = new World(new Vector2(0, 0), true);

      spriteBatch = new SpriteBatch();
      spriteBatch.setProjectionMatrix(camera.combined);

      player = new Player(spriteBatch, world, WTB);

      bottomLeft = new Vector2(-Gdx.graphics.getWidth() / 2 * WTB, -Gdx.graphics.getHeight() / 2 * WTB + player.body.getPosition().y);
      bottomRight = new Vector2(Gdx.graphics.getWidth() / 2 * WTB, -Gdx.graphics.getHeight() / 2 * WTB + player.body.getPosition().y);
      borderShape = new ChainShape();
      borderShape.createChain(new Vector2[] { bottomLeft, bottomRight });
      borderFixture = new FixtureDef();
      borderFixture.density = 5;
      borderFixture.friction = .1f;
      borderFixture.restitution = .9f;
      borderFixture.shape = borderShape;
      borderBody = new BodyDef();
      borderBody.type = BodyDef.BodyType.StaticBody;

      ground = world.createBody(borderBody);
      ground.createFixture(borderFixture);
      borderShape.dispose();

      //To keep here as clean as possible, I made another method for controls.
     controls();

      //TESTING
     platforms = new Array<Platform>();
      testPlatforms.add(new Platform(spriteBatch, world, WTB, -2, 9, 19));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, 0, 4, 6));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, 0, 4, 12));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, 0, 3, 32));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, 2, 7, 29));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, 4, 10, 50));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, -10, 3, 80));
      testPlatforms.add(new Platform(spriteBatch, world, WTB, -1, 3, 110));
   }

   public void controls() {
      Gdx.input.setInputProcessor(new InputProcessor() {
//touchUp, touchDragged, touchDown, scrolled, mouseMoved, keyUp, keyTyped are empty.

         @Override
         public boolean keyDown(int keycode) {
            switch (keycode) {
            case Keys.W:
               player.body.applyForceToCenter(0, 1000, true);
               break;
            case Keys.A:
               player.body.applyForceToCenter(-500, 0, true);
               break;
            case Keys.S:
               player.body.applyForceToCenter(0, -500, true);
               break;
            case Keys.D:
               player.body.applyForceToCenter(500, 0, true);
               break;
            default:
               break;
            }
            return true;
         }
      });
   }
//Hide, pause, resume and dispose are empty methods for now.
}


And this is my Platform class, which I use to create platforms which the player should avoid (Originally the player would jump on that, but since this is a test project now, I am not sure what to do with these.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
public class Platform {

   public final float WTB;

   // Drawing
  public Sprite sprite;
   public Texture texture;
   public TextureRegion region;
   public SpriteBatch spriteBatch;

   // Box2D
  public Body body;
   public FixtureDef fixtureDef;
   public BodyDef bodyDef;

   public World world;
   public float x1,x2,y;

   public Platform(SpriteBatch spriteBatch, World world, float WTB,
         float x1, float x2, float y) {
      this.WTB = WTB;
      this.spriteBatch = spriteBatch;
      this.world = world;
      this.x1 = x1;
      this.x2 = x2;
      this.y = y;
     
      texture = new Texture("data/bridgeLogs.png");
      texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
      texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
      region = new TextureRegion(texture,0f,0f,(x2 - x1)/texture.getWidth()/WTB,1f);
      sprite = new Sprite(region);
      sprite.setSize(region.getRegionWidth(), region.getRegionHeight());
      sprite.setScale(WTB);
     
      PolygonShape shape = new PolygonShape();
      shape.setAsBox((x2 - x1)/2, region.getRegionHeight()*WTB/2, new Vector2((x1+x2)/2,y), 0);
     
      fixtureDef = new FixtureDef();
      fixtureDef.density = 1;
      fixtureDef.friction = .2f;
      fixtureDef.restitution = .4f;
      fixtureDef.shape = shape;
      bodyDef = new BodyDef();
      bodyDef.type = BodyDef.BodyType.StaticBody;
      bodyDef.position.set(x1, y);
      body = world.createBody(bodyDef);
      body.createFixture(fixtureDef);
      body.setFixedRotation(true);

      }
   }

   public void render() {
// TRIED this in many different ways, like subtracting the half of the sprite height and width, still got no luck
     sprite.setOrigin(body.getPosition().x, body.getPosition().y);
      sprite.setPosition(body.getPosition().x, body.getPosition().y);
      sprite.setRotation(body.getAngle() * MathUtils.radDeg);
      sprite.draw(spriteBatch);
   }



If you are willing to run this, you don't need my player class, you can just make the camera move in y axis.
23  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] Anybody can explain U, V, U2 and V2 values? on: 2014-02-20 18:24:49
So basically, you just pick the places a player can go (and for the sake of my explaining, put them in an array), and say, if it goes to up, you delete the bottom image coordinates from the array and add a new coordinate which is higher.
If it goes to left, you delete the right one, your middle one becomes right one, your left one becomes middle one (because that's where your player is) and you just create a new left.

I don't know if it's because I heard your solution or it is really the only way, but I it makes sense to me to use this Cheesy

I'll stick to OpenGL wrapping method for now, but for an infinite background, I think I'd have to switch to your method.
24  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] Anybody can explain U, V, U2 and V2 values? on: 2014-02-19 16:06:23
Thanks nerb. Thanks to Phibedy, I discovered the UV coordinates which I kinda ignored and stayed away until now Smiley
So, this should also mean the same with Vector2 normalize method. Good to know.

Here is my other question, you guys know that my initial problem was to repeat the background. I set the background using this method:
1  
spriteBatch.draw(texture, x, y, width, height, u, v, u2, v2);

And of course, setWrap method is used as well.

But when I try to render sprites in the same manner, I cannot do this, because there is not a similar method for this. What should I do to draw the sprites like that background?
25  Discussions / Business and Project Management Discussions / Re: (PAID) testers wanted on: 2014-02-19 10:23:51
Can test it for Mac if you need testers.
26  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] Anybody can explain U, V, U2 and V2 values? on: 2014-02-19 10:03:22
UV are the koordinates of your texture normalised in each component. u-v is top right, u2-v2 is bottom left corner.
Just read that article: https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Textures#wiki-wrap-modes

But for accomplishing your task you might wanna use gl_repeat: http://open.gl/textures
Thanks. I am already using GL20.GL_REPEAT. I'm also experimenting with GL_CLAMP_TO_EDGES to see differences.

Thanks to the article link you gave me, I could search with better keywords. I came to conclusion that if I make u and v 0 and u2 and v2 2, it will repeat the image twice vertically and horizontally. So, I am getting 4 images.

But, what do you mean with the word "normalized"?

Or you could create a simple if statement and for loop, basically just draw 3 background images, one behind the player out of view, one in view, one ahead.

This seemed to work for me, can't imagine it is expensive to draw considering how many sprites a game actually processes.
Thanks to Phibedy, I'm able to do what I want, with some problems I can fix with some trial-error. But I'm interested in learning about your method. Can you elaborate?
27  Java Game APIs & Engines / Engines, Libraries and Tools / [LibGDX] Anybody can explain U, V, U2 and V2 values? on: 2014-02-19 07:44:40
Here is a draw method we can use in LibGDX:
1  
spriteBatch.draw(texture, x, y, width, height, u, v, u2, v2);


I wanted to make a background draw more than once. I mean, the player will move and background will not, but instead a new image will be drawn when the first one's borders are on the screen.

I could do it with this method. But I am curious, because I couldn't really understand what it does. My background image is a 128x128 one, and it is drawn 4 times on the screen. I can manipulate u, v, u2 and v2 values and make it draw once or twice. But I really don't know which one to manipulate to get the results I want.

I have no particular result I want to get, I just want to know what the values in this constructor do. I especially want to know what u, v, u2 and v2 does. Searched the internet, everybody just gave the OPs numbers instead of an explanation. I need explanations.
28  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-18 17:34:57
Guys, check reply #16 Smiley I took the advice of the people who replied to the thread and modified it to my needs.

@GoToLoop,
Yes I was. It was a dirty template which I was going to fix as much as I could, and yes, I fixed them.
Also, my point when I said they are meant to be constants was that they are constants in the main game class and I typed them all in capitals so that I don't forget about the constants in the main class and give different values in one of the other classes. But I made them final in my code, maybe I posted a previous version of the code.

@Gibbo3771,
Yes, what you suggested would be easier and maybe better. But I thought "I'll change the attributes of those BodyDef and FixtureDefs, so why not just initialize them in the subclasses?"
That idea comes from my laziness. Instead of forgetting the attributes of those objects and then wondering why my characters don't act the way I set them up, I thought it would be good if I just write 2-3 more lines of codes in the subclasses. So if I forget those, it will just give me a null pointer error instead of weird behavior.

Thanks guys for pointing out the errors and making suggestions to make it better Smiley My problem is fixed for now, but please feel free to add anything else.
29  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-18 03:36:06
Here is what I have done to my classes:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class Entity {
   // Variables
 
   public Entity(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX, float BOX_TO_WORLD){
        //Some arguments which will be same for to all entities.
     this.spriteBatch = spriteBatch;
      this.WORLD_TO_BOX = WORLD_TO_BOX;
      this.BOX_TO_WORLD = BOX_TO_WORLD;
   }

   public void init (Texture texture, SpriteBatch spriteBatch, World world,
         FixtureDef fixtureDef, BodyDef bodyDef, Shape shape, float WORLD_TO_BOX, float BOX_TO_WORLD) {
      // These are what I want to define in subclasses, not in the main game screen.
     body = world.createBody(bodyDef);
      body.createFixture(fixtureDef);
      sprite = new Sprite(texture,0,0,16,32);
      //Shortened the code

   }


And this is one of the subclasses:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public class Player extends Entity{
   
   FixtureDef fixtureDef;
   BodyDef bodyDef;
   Texture texture;
   PolygonShape shape;
   
   public Player(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX,
         float BOX_TO_WORLD) {
      super(spriteBatch, world, WORLD_TO_BOX, BOX_TO_WORLD);
      shape = new PolygonShape();
      shape.setAsBox(.25f, .5f);
      fixtureDef = new FixtureDef();
      fixtureDef.density = 5;
      fixtureDef.friction = .1f;
      fixtureDef.restitution = .8f;
      fixtureDef.shape = shape;
      bodyDef = new BodyDef();
      bodyDef.type = BodyDef.BodyType.DynamicBody;
      bodyDef.position.set(5, 5);
      texture = new Texture("data/a.png");
      super.init(texture, spriteBatch, world, fixtureDef, bodyDef, shape, WORLD_TO_BOX, BOX_TO_WORLD);
      // I made it like this, because this one won't have another subclass.
               // If I was going to make a subclass for this, this class' structure would be similar to Entity class.
  }


And I can call this easily like this:
1  
Player player = new Player(spriteBatch, world, WTB, BTW);
30  Discussions / Miscellaneous Topics / Re: Sorry to those who suffered from me ;) on: 2014-02-17 22:00:51
Your problem is the problem of all non-native English speaking people.

It is hard not to think in your language and then translate it into English. And, unless you live in an English speaking country (where your only chance is to speak in English all the time), this will be your (our) problem all the time.

I am a translator, mainly translating medical  articles. Thinking in Turkish (my language) and then translating it into English is not a problem in medical area. Because medical vocabulary is more Latin than English or any other language. So I'm fine there.

But I'm somehow used to think in English. Especially when I try to remember the meaning of a word in English, I tend to ask the question in English in my mind. But that is not the case for most of the other topics.

And there's the emphasis issue. Non-native speakers of any languages would place the emphasis on the wrong words most of the time, no matter how experienced they are.

I can guarantee that any article written by me will be understood better by a Turkish person regardless of the quality of the usage of English in the text. So, zero mistakes in English doesn't mean that everybody will understand what you meant.

This is why most of the questions have long explanations, or subsequent questions. I am thinking that I asked just what is on my mind, but another person gets it in a whole different way.

So, that would be F for me. I don't care. Probably as a non-native English speaker, I understand what you say better than the native English speakers Smiley

About google translation, it depends on the language pairs. If sentence structures are similar between the languages, then it does a good job, but if the sentence structure is different, Google Translation is worse than your own words. I reject proofreading projects as soon as I realize that it is a machine translation Smiley

Anyway, this problem would have less importance if we could set our primary language in our profiles. It won't make it go away, but it would make it easier.
Pages: [1] 2 3 4
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!