Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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]
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 Smiley. I will test it out after a few hours when I'm back home.
I will report here how's it going Smiley.

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
newAngle = angle + (float)Math.PI

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

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
Rotate 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 Smiley. 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.

Click to Play


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 Smiley.

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.  Roll Eyes

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 Smiley.

_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/3KAaamm

So 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 Smiley

_Tumppu_
9  Game Development / Newbie & Debugging Questions / Re: Delayed rotation on: 2012-09-28 04:49:32
Yeh, I noticed that little bug Smiley. Gonna try and fix it by myself Tongue. Thank you very much again Smiley
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 Smiley

Thanks dude! That works veeery nicely! Smiley
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 Smiley

Heh okay thx. That's seems easier Smiley
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 Smiley, 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 Smiley.

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. Smiley

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

Thanks in advance Smiley

edit. I try to explain better...

The cannon is now facing direction x,y
When I move the mouse, the facing direction changes of course to nx,ny.
I want it to be so that cannon slowly rotates to the new facing direction... Smiley
Pages: [1]
 
nelsongames (17 views)
2018-04-24 18:15:36

nelsongames (13 views)
2018-04-24 18:14:32

ivj94 (587 views)
2018-03-24 14:47:39

ivj94 (49 views)
2018-03-24 14:46:31

ivj94 (400 views)
2018-03-24 14:43:53

Solater (64 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (175 views)
2018-03-02 22:15:33

buddyBro (723 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!