Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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  
  [FIXED] Mouse Coords in a tiled world.  (Read 4058 times)
0 Members and 1 Guest are viewing this topic.
Offline Brynn
« Posted 2014-04-15 23:23:40 »

Hey guys. I need some help with my platformer game, you see- I cannot figure out at all how to find where the mouse is on the screen. You may be saying:
1  
Well, just add them mouse coords and camera coords, then it will work.

but no. It doesnt. I have no clue why! Let me keep in mind, it works if I use the player's x,y I just cant add the mouse factor into that.

Since I probally havent given enough info on the code itself, you can generalize, but this is what ive tried so far.

WORKS.
1  
actionPos =  new Point(x,y);


DOESNT WORK. WELL, SORT OF
1  
actionPos =  new Point(mouse.x+camera.x,mouse.y+camera.y); //camera is just the players x and y with half the screen subtracted


Any suggestions? Now here is the silly thing. It works, but the action position races ahead of the cursor. Basically at 0,0 on the screen, where camera.x, camera.y is, it is 100% accurate, but 2 pixels away, it may be 4-6 pixels away, at about half the screen its a quarter screen away from the cursor, etc.

I hope you guys can help. Ill give any more stuff on the issue if its needed! This is urgent!
Offline CodeHead

JGO Knight


Medals: 52


From rags to riches...to rags.


« Reply #1 - Posted 2014-04-15 23:59:32 »

Are you doing any sort of scaling when you render that you haven't accounted for when calculating your mouse/world position?

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline achap1989

Senior Newbie


Medals: 1



« Reply #2 - Posted 2014-04-16 00:02:09 »

IF you are scaling your tiles you will need to dived the x or y position by the scale amount.

Example if I am scaling by 32 I would take x/32  or y/32
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online LiquidNitrogen
« Reply #3 - Posted 2014-04-16 00:06:19 »

my program has an issue like that when the window is different size than the view port, the drawing is scaled up and down nicely, but the mouse co-ords are still relative to the physical screen resolution.
Offline Opiop
« Reply #4 - Posted 2014-04-16 03:30:48 »

Quote
Already fixed by the engine, no matter the screen size the end will always be 1920 or 1080 depending on the axis. The engine also tries to render it at this however the field of view is  not.

Just want to point out, that statement is completely wrong. You cannot have a window that is less than 1920x1080 pixels still take up 1920x1080 pixels. If a window is 800x600, how the hell could you still have 1920x1080 pixels within the window? Its physically impossible.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 167
Projects: 5
Exp: 6 years



« Reply #5 - Posted 2014-04-16 04:13:29 »

Maybe he means in-game units?
Offline HeroesGraveDev

JGO Kernel


Medals: 382
Projects: 11
Exp: 4 years


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


« Reply #6 - Posted 2014-04-16 04:47:09 »

my program has an issue like that when the window is different size than the view port, the drawing is scaled up and down nicely, but the mouse co-ords are still relative to the physical screen resolution.

Try calling glViewport with the window size.

Offline trollwarrior1
« Reply #7 - Posted 2014-04-16 04:49:49 »

You might need to be doing x-camera.x,y-camera.y instead of addition.
Offline Opiop
« Reply #8 - Posted 2014-04-16 21:23:04 »

Quote
it only shows a fixed amount
You mean it doesn't scale the objects in game, correct? I would highly advise against this. If someone plays in a different screen ratio, all your objects are going to look distorted. Minecraft and Terraria handle resizing the correct way by scaling, I have no idea why that would be a bad thing.
Offline Opiop
« Reply #9 - Posted 2014-04-16 21:30:21 »

Ah I see what you mean. That doesn't happen with Minecraft or Terraria, but no matter, I won't derail your thread anymore.

Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

Solater (972 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!