Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Y-axis acting differently from x-axis in libgdx  (Read 1552 times)
0 Members and 1 Guest are viewing this topic.
Offline Powersource

Junior Newbie





« Posted 2013-01-28 08:18:30 »

First of all, hi, new here.

This doesn't have to do with different origins in the coordinate systems (afaik), I already accounted for that.
A previous post on the issue. http://www.reddit.com/r/javahelp/comments/174i55/yaxis_movement_behaving_differently_from_xaxis/
The code. http://pastie.org/5894953
I'm using libgdx for this and it's just an icon that you can move either by using your arrow keys or by holding down your mouse button. The problem is that when I use setPosition() in both movement-ways the function seems to add/remove a couple of pixels. I have printed the position before setting it and once I set it it doesn't end up where it should be.
It's as if when I use setPosition() it multiplies the Y-value by 1.1-ish in both ways I implemented it. I don't have 1.1 (or any number like it) anywhere in the code and when I check the variable right before sending it to setPosition it is correct. Setting it to fullscreen didn't help.
Offline ReBirth
« Reply #1 - Posted 2013-01-28 08:38:10 »

Actually your movement code is very complicated. I don't know why you need to multiply by 1f and divide by width or height.

I didn't run your code, but my advice is try to don't worry about scaling first (remove OrthographicCamera) and avoid the "1f / Gdx.graphics.getHeight()/getWidth()".

One more, your diag never is hardly become 1 or -1 as keypressed will trigger continuely.

Offline Powersource

Junior Newbie





« Reply #2 - Posted 2013-01-28 18:44:03 »

Yes I could probably simplify it a bit. The reason I added * 1f was because I needed it to be a float but I should probably just use (float) haha. The reason I divide by height and width is because the coordinates are between 0 and 1. 0 is one end of the screen and 1 is the other. I calculate the coordinates of the object and then I divide it to get the coordinate that the system wants. But I think this is all irrelevant, since the code for the x and y-axes are identical except for x and width being replaced by y and height. The x-axis works perfectly so by my logic the y-axis should work perfectly too. But it won't Sad
    Diag is supposed to become sqrt(0.5) and when I printed it before it seemed to work. Although I'll test that once this problem is solved since now the speed when going up and down is different from going right to left so I can't really measure it properly.
    I'll try commenting out the orthographic camera but that was in the example program when I got it so I'd expect it to work.
    Edit: The only thing that happened when I removed the camera was that nothing appeared.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2013-01-30 03:17:09 »

Try to use absolute coordinate for now to testing purpose. If it works, there's something wrong in that calculation.

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #4 - Posted 2013-01-30 03:29:08 »

Your problem is that you're not separating the logic from the rendering.

Scaling should be done when rendering, not when calculating the positions.

Offline Powersource

Junior Newbie





« Reply #5 - Posted 2013-02-11 08:05:18 »

So, I found this post. http://stackoverflow.com/questions/8104364/apply-pixel-coordinates-to-screen-coordinates
I did the unproject thing and now it works! (not entirely sure what it does though)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!