Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (748) Games in Android Showcase (226) games submitted by our members Games in WIP (834) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
 1 Game Development / Newbie & Debugging Questions / Re: Libgdx, Box2D, Box2dLight on: 2018-02-06 17:15:33 Thanks for the input, yeah the code is a little messy right now (sorry bout that). I will try those suggestions.Cheers_Tumppu_
2  Game Development / Newbie & Debugging Questions / Re: Libgdx, Box2D, Box2dLight on: 2018-02-06 16:16:37
newAngle = angle + (float)Math.PI

Hi there, okay thanks . I will test it out after a few hours when I'm back home.
I will report here how's it going .

Cheers

_Tumppu_

Damn, still not working :l

code:

 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 `   public void rotate() {      Vector3 worldCoords = camera.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(), 0));      Vector2 vec2 = new Vector2(arm.getWorldCenter().x - worldCoords.x,arm.getWorldCenter().y- worldCoords.y);      vec2.set(vec2.x, vec2.y);            float angle = (float) Math.atan2(arm.getWorldCenter().y - worldCoords.y, arm.getWorldCenter().x - worldCoords.x);            float newAngle = angle + (float)Math.PI;      arm.setTransform(new Vector2(arm.getPosition().x, arm.getPosition().y), newAngle);            light.attachToBody(arm);      //light.setDirection(arm.getAngle() + 135);      light.setDirection(newAngle);                  //System.out.println(angle);      /** double angle2 = arm.getAngle();      angle2 = normalRelativeAngle(angle2);      System.out.println(angle2);      light.attachToBody(arm); **/             /**  final float angle3 = arm.getAngle();         final float sin = MathUtils.sinDeg(angle3);         final float cos = MathUtils.cosDeg(angle3);         final float x = arm.getPosition().x + 1 * cos - 1 * sin;         final float y = arm.getPosition().y + 1 * sin + 1 * cos;         light.setPosition(x, y);         light.setDirection(angle3); **/                        }`

Cheers

_Tumppu_
 3 Game Development / Newbie & Debugging Questions / Re: Libgdx, Box2D, Box2dLight on: 2018-02-06 14:39:00 Quote from: orange451 on 2018-02-06 14:30:30newAngle = angle + (float)Math.PIHi there, okay thanks . I will test it out after a few hours when I'm back home. I will report here how's it going . Cheers _Tumppu_
4  Game Development / Newbie & Debugging Questions / Re: Libgdx, Box2D, Box2dLight on: 2018-02-06 07:13:02
Also tried somethin:

 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 `   public void rotate() {      Vector3 worldCoords = camera.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(), 0));      Vector2 vec2 = new Vector2(arm.getWorldCenter().x - worldCoords.x,arm.getWorldCenter().y- worldCoords.y);      vec2.set(vec2.x, vec2.y);            float angle = (float) Math.atan2(arm.getWorldCenter().y - worldCoords.y, arm.getWorldCenter().x - worldCoords.x);            arm.setTransform(new Vector2(arm.getPosition().x, arm.getPosition().y), angle);            float newAngle = (float) Math.PI / 180 * angle;      light.setDirection(newAngle);      System.out.println(newAngle);                  //System.out.println(angle);      /** double angle2 = arm.getAngle();      angle2 = normalRelativeAngle(angle2);      System.out.println(angle2);      light.attachToBody(arm); **/             /**  final float angle3 = arm.getAngle();         final float sin = MathUtils.sinDeg(angle3);         final float cos = MathUtils.cosDeg(angle3);         final float x = arm.getPosition().x + 1 * cos - 1 * sin;         final float y = arm.getPosition().y + 1 * sin + 1 * cos;         light.setPosition(x, y);         light.setDirection(angle3); **/                        }`

Output is intredasting

 1  2  3  4  5  6 `-0.04592159-0.04593443-0.045944814-0.0459527-0.045958187-0.045961812`

Just can't get it work :/

Cheers

_Tumppu_
 5 Game Development / Newbie & Debugging Questions / Re: Libgdx, Box2D, Box2dLight on: 2018-02-06 06:02:51 Quote from: bmanmcfly on 2018-02-06 03:41:43Rotate 180... 1pi Sorry, I see you tried that.  Have you tried just putting the body to the opposite point?  Like at width - X and height - y?  Seems that would be a way of butchering things into what you want?(Sorry, I don't have a lot of experience with box2d, it didn't produce an effect I had found desirable and ripped it out, just that's something I would try)Hey, and thanks for your input. Sorry, really didn't understand what u mean. Do u mean the light at the opposite point? My char is built up from 4 bodies (body, head, weapon & arm). Or do u mean the arm should be attached like the way u discribed? Sorry I'm little confused . Wierd thing thou, the arm is working nicely and rotating all the 360 degrees. Can't just understand why the light won't behave the same way. Cheers_Tumppu_
6  Game Development / Newbie & Debugging Questions / Libgdx, Box2D, Box2dLight on: 2018-02-05 13:18:33
Hello there

I have a little problem with Box2dLight. I want it to rotate to the direction where the hand is pointing (follow the mouse pointer).

So I made a little gif to show ya how it's behaving.

As u can see, it's pointing opposite direction :l.

So this is how I create my light:

 1  2  3  4  5 `         light = new ConeLight(ray,100, Color.WHITE, 200,arm.getPosition().x,arm.getPosition().y, 360, 20);         light.attachToBody(arm);         light.setColor(Color.BLUE); `

This is how I rotate the arm:

 1  2  3  4  5  6  7 `public void rotate() {      Vector3 worldCoords = camera.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(), 0));      Vector2 vec2 = new Vector2(arm.getWorldCenter().x - worldCoords.x,arm.getWorldCenter().y- worldCoords.y);      vec2.set(vec2.x, vec2.y);float angle = (float) Math.atan2(arm.getWorldCenter().y - worldCoords.y, arm.getWorldCenter().x - worldCoords.x);                arm.setTransform(new Vector2(arm.getPosition().x, arm.getPosition().y), angle);}`

And this is where rotating is happening:

 1  2  3  4  5  6  7  8  9  10  11  12  13 `   public boolean mouseMoved(int screenX, int screenY) {            mx = Gdx.input.getX();      my = Gdx.input.getY();         light.setPosition(arm.getPosition().x, arm.getPosition().y);         System.out.println(Math.toDegrees(arm.getAngle()));      rotate();            return false;   }`

So what I want, is that the licghtcone would point always to a mouse pointer. I read that, when attaching light to a body, it will automatically rotate to bodys direction. I have tried like changig the light direction and so, but it always seems to rotate just 180 and to an opposite direction. If u have any ideas, I would be glad .

Cheers

_Tumppu_
 7 Game Development / Newbie & Debugging Questions / Re: LibGDX tilemap smoothing on: 2016-11-19 19:40:26 Oh, had wrong link first, not the .png one. Now, the pic works.  So bilinear filtering, as it is described "Bilinear filtering is a texture filtering method used to smooth textures when displayed larger or smaller than they actually are. Most of the time, when drawing a textured shape on the screen, the texture is not displayed exactly as it is stored, without any distortion."I really dont see, how could I use this with two tiles transition. But oh well, have to do some research more. Thanks for the input tho . _Tumppu_
 8 Game Development / Newbie & Debugging Questions / LibGDX tilemap smoothing on: 2016-11-19 15:11:15 Hi again, it's been a while. Soo, I have been messing around with a Simplex Noise, and made kinda like a map.It's built with tiles in 2D array as the pic shows, so it really isn't that good looking.  edit. hmmmh. Forumn doesn't support ImgUr? anyway. here is the pic: http://imgur.com/3KAaammSo I was just wondering if someone could give me some pointers on how to kinda like smooth tiles out, blending or so. I have read about texture splattering and have tried to implement some with Alpha mask texture. With one tile it's fine (because they are top on each other), but I just cant get it, how Can I smooth transfer like grass -> stone [grass][stone] if they are next to each other . Should I some how check the neighbours and create a mask that blends with neighbours texture? Or is there some other way? No, I dont want to draw tiles for different transforms or so. Thanks in advance _Tumppu_
 9 Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-28 04:49:32 Yeh, I noticed that little bug . Gonna try and fix it by myself . Thank you very much again
10  Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-27 21:04:25
Haha

Well you have this.angle.
You could make another variable this.currentangle

then use something like this:

 1  2  3  4  5  6  7  8 `float diff = this.angle - this.currentangle;if(diff < 0){ diff += (float)Math.PI * 2; }if(diff < Math.PI){    this.currentangle += 0.01f;}else{    this.currentangle -= 0.01f;}`

You check the diffrence between the current and the destination angle.
If its close to the right, move right, else move left.

I always mess up + and - so you might need to switch the variables

Thanks dude! That works veeery nicely!
11  Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-27 20:56:41
Haha

Well you have this.angle.
You could make another variable this.currentangle

then use something like this:

 1  2  3  4  5  6  7  8 `float diff = this.angle - this.currentangle;if(diff < 0){ diff += (float)Math.PI * 2; }if(diff < Math.PI){    this.currentangle += 0.01f;}else{    this.currentangle -= 0.01f;}`

You check the diffrence between the current and the destination angle.
If its close to the right, move right, else move left.

I always mess up + and - so you might need to switch the variables

Heh okay thx. That's seems easier
 12 Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-27 18:15:24 Ugh, dunno how to implement this....
 13 Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-27 16:20:06 Well thanks , I will take a look at it
14  Game Development / Newbie & Debugging Questions / Delayed rotation on: 2012-09-27 16:06:48
Hi there all

This is my first post and don't care about my spelling, English is not my native
language .

So I'm creating just a little tank game, everything is fine, tank is moving and cannon turning.

The problem is

 1  2  3  4  5  6  7 `   public void setDirection(float x, float y) { // parametres are mouse x,y         float rx = x - this.getX();   float ry = y - this.getY();   this.angle = (float)Math.atan2(ry, rx); // cannon angle}`

This rotates the cannon okay, but, I would like to have some kind of delay to that turning (I mean, now
it's instant.
How is such a thing even possible? Somehow with delta time? I suck at math and physics sooo.

Well, if someone could help, I would really appreciate that!