Is it possible to modify LibGDX source code?

Anything libgdx related goes here!

Is it possible to modify LibGDX source code?

Postby xpdt » Mon May 13, 2019 4:17 pm

Hi
I need to add a method to the Stage.java. Some objects in this class are private and i do not have access to them So i need to modify this file to add my methods or public the objects.
xpdt
 
Posts: 82
Joined: Mon Jul 04, 2016 2:29 am

Re: Is it possible to modify LibGDX source code?

Postby david_dev » Mon May 13, 2019 4:39 pm

You can clone the repository and change anything you want, but I think that it's better you explain your "ideas" and/or publish a PR so all the rest of developers can benefit for the improvements.
david_dev
 
Posts: 20
Joined: Fri Mar 04, 2016 5:47 pm

Re: Is it possible to modify LibGDX source code?

Postby xpdt » Mon May 13, 2019 7:58 pm

david_dev wrote:You can clone the repository and change anything you want, but I think that it's better you explain your "ideas" and/or publish a PR so all the rest of developers can benefit for the improvements.


How do I do this? I searched the internet but did not find anything.

There is touchDown, touchDragged and touchUp methods in Stage class.
I want to simulate the touch by using these methods, but for some reason I want to send the stage position, not the screen position. So i need to create 3 new methods.
xpdt
 
Posts: 82
Joined: Mon Jul 04, 2016 2:29 am

Re: Is it possible to modify LibGDX source code?

Postby vik182 » Mon May 13, 2019 8:00 pm

Mmmm I do not know if you can inherit from Stage and implement the methods you need.
vik182
 
Posts: 44
Joined: Wed Jul 04, 2018 9:44 pm

Re: Is it possible to modify LibGDX source code?

Postby xpdt » Mon May 13, 2019 8:10 pm

vik182 wrote:Mmmm I do not know if you can inherit from Stage and implement the methods you need.


I need touchFocuses that is private in Stage.java and I do not have access to it.
xpdt
 
Posts: 82
Joined: Mon Jul 04, 2016 2:29 am

Re: Is it possible to modify LibGDX source code?

Postby evilentity » Mon May 13, 2019 8:13 pm

This is easy enough to do without anything fancy
Code: Select all

private static class FakeStage extends Stage {
   private Vector2 v2 = new Vector2();
   public void fakeTouchDown (int stageX, int stageY, int pointer, int button) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchDown((int)v2.x, (int)v2.y, pointer, button);
   }

   public void fakeTouchDragged (int stageX, int stageY, int pointer) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchDragged((int)v2.x, (int)v2.y, pointer);
   }
   
   public void fakeTouchUp (int stageX, int stageY, int pointer, int button) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchUp((int)v2.x, (int)v2.y, pointer, button);
   }
}
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4854
Joined: Wed Aug 24, 2011 11:37 am

Re: Is it possible to modify LibGDX source code?

Postby xpdt » Mon May 13, 2019 9:39 pm

evilentity wrote:This is easy enough to do without anything fancy
Code: Select all

private static class FakeStage extends Stage {
   private Vector2 v2 = new Vector2();
   public void fakeTouchDown (int stageX, int stageY, int pointer, int button) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchDown((int)v2.x, (int)v2.y, pointer, button);
   }

   public void fakeTouchDragged (int stageX, int stageY, int pointer) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchDragged((int)v2.x, (int)v2.y, pointer);
   }
   
   public void fakeTouchUp (int stageX, int stageY, int pointer, int button) {
      stageToScreenCoordinates(v2.set(stageX, stageY));
      touchUp((int)v2.x, (int)v2.y, pointer, button);
   }
}

Thanks But there is a problem with this solution Because the coordinates change a bit.
For example if we pass (550, 550) the result will be (550.0,548.00006) And this is not acceptable to my game.
xpdt
 
Posts: 82
Joined: Mon Jul 04, 2016 2:29 am

Re: Is it possible to modify LibGDX source code?

Postby evilentity » Mon May 13, 2019 10:11 pm

Then step thru the code and figure out where to +1 to fix that.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4854
Joined: Wed Aug 24, 2011 11:37 am

Re: Is it possible to modify LibGDX source code?

Postby xpdt » Mon May 13, 2019 10:22 pm

In fact, I want to save all the touches of each frame in a file when the user is playing, and later, using this file, I can simulate all the touches in each frame and simulate the whole game. This file can be shared so other users can watch the game. But the screen size of the devices varies, and we can not use the screen coordinates. For this reason, I want to use the stage coordinates directly.
xpdt
 
Posts: 82
Joined: Mon Jul 04, 2016 2:29 am

Re: Is it possible to modify LibGDX source code?

Postby shatterblast » Tue May 14, 2019 3:09 am

xpdt wrote:But the screen size of the devices varies, and we can not use the screen coordinates. For this reason, I want to use the stage coordinates directly.

That will be a problem with your Viewport and Camera then. If stuff gets re-sized, you will have an issue as you try to round up or down to get the nearest value. Your Viewport makes the largest difference. I personally use ExtendViewport for my battle scenes for a close 1 to 1 value, but the background image must basically stay larger than the viewable area of your ExtendViewport. While this may correctly function for most phones, a scant few will provide trouble regardless of what you may want to try, like from certain old Samsung firmware.

https://github.com/libgdx/libgdx/wiki/Viewports#extendviewport
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Magnesus and 1 guest