Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 4562 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.
The code.
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 /".

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: 382
Projects: 11
Exp: 4 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.
I did the unproject thing and now it works! (not entirely sure what it does though)
Pages: [1]
  ignore  |  Print  

EgonOlsen (77 views)
2018-06-10 19:43:48

EgonOlsen (57 views)
2018-06-10 19:43:44

EgonOlsen (77 views)
2018-06-10 19:43:20

DesertCoockie (259 views)
2018-05-13 18:23:11

nelsongames (157 views)
2018-04-24 18:15:36

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

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

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

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

Solater (174 views)
2018-03-17 05:04:08
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 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‑
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!