Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  [Solved] Slick 2D Game Scaling and Rotating Problems  (Read 7275 times)
0 Members and 1 Guest are viewing this topic.
Offline duce

Senior Newbie





« Posted 2011-09-13 10:47:13 »

I have just finished the mouse input for my game. My "player" sprite will always look at the mouse position. I am now trying to set up a zoom and translate to center the "player" sprite. I want to have it so when the sprite moves, it will stay exactly center in the frame. I sort of have one working, but when I start moving around, the mouse part gets all screwed up. Also, I can't get it perfectly centered in the frame. Is there some kind of formula, or do I have to eye it out.

Edit: Solved!

My old atan2 function used the center of the sprite minus the mouse position to get the rotation. It worked fine when it was in the center, but when I moved around with the sprite, it got messed up.
My new atan2 function uses the center of the screen (400 x 300 in my case) minus the mouse points to get the rotation. Works fine now.
Offline Cero
« Reply #1 - Posted 2011-09-13 13:31:49 »

I'm guessing the problem is the offset, but we would need some more info or pics or vids or whatever

hard to guess whats wrong, if you only say "it gets screwed up" =D

Offline duce

Senior Newbie





« Reply #2 - Posted 2011-09-13 19:04:18 »

http://www.youtube.com/watch?v=F_meSUVsoGQ

The first part shows the way it's supposed to be, then it shows the corners, where it gets messed up.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2011-09-13 19:24:17 »

yeah its exactly what I said, you need to add/subtract the camera position from the calculation

the sprites location should absolute, the camera moves and the mouse location is local... so whenever you have mouseX and mouseY you have to add the camera/offset x and y

Offline Cero
« Reply #4 - Posted 2011-09-13 19:31:17 »

maybe clearer: when you use the mouse location values, you have to use the mouse's absolute position on the map, not local position on the screen

and that is camera.x + local mouse position.x  and y the same

Offline duce

Senior Newbie





« Reply #5 - Posted 2011-09-13 19:50:45 »

How do I get absolute positioning compared to screen positioning?
Offline Cero
« Reply #6 - Posted 2011-09-13 20:46:43 »

How do I get absolute positioning compared to screen positioning?
Quote
and that is camera.x + local mouse position.x  and y the same

Offline duce

Senior Newbie





« Reply #7 - Posted 2011-09-13 23:45:11 »

What do I use for camera.x? I tried getting the x in g.translate(x, y), but that just messed it up completely.
Offline Cero
« Reply #8 - Posted 2011-09-14 00:08:44 »

so you are using g translate in this example huh

well that value that you have translated g in total plus or minus you have to add to mouse

Offline duce

Senior Newbie





« Reply #9 - Posted 2011-09-14 00:13:32 »

Okay, I will.
Quote
so you are using g translate in this example huh
So, there is another way of doing it? g.translate() is the only way I know how.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline duce

Senior Newbie





« Reply #10 - Posted 2011-09-14 01:55:24 »

Ah, works now. Still, is there a better way than g.translate() that I should know about?
Offline Cero
« Reply #11 - Posted 2011-09-14 12:03:43 »

Well thats not really how I would do it.

all my objects have absolute locations on the map

then you have a camera, which is just a rectangle with the size of the screen
you move the player and adjust the camera to look at the player

now at rendering you render everything with that camera.

first, to not render stuff that wouldn't be on the screen, you say, well is the object inside the camera
basically camera.intersects(object)
and for every object that is, you render it with its absolute location minus the camera's location

It's just a concept that came to me naturally and I have been using it every since, it's not a way I read somewhere - but it might be the same or very similar to "what you're supposed to do"

anyway, using this you can also have parallax scrolling with layers and different cameras easily, as well as scenes in which the camera would look/shift to something other than the player

Offline duce

Senior Newbie





« Reply #12 - Posted 2011-09-14 18:41:58 »

That is interesting, but how do you make it so the screen is only inside the rectangle.
Offline R.D.

Senior Devvie


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #13 - Posted 2011-09-14 18:45:21 »

in Slick? setClip on the given Graphics object inside a render method Smiley
Offline Cero
« Reply #14 - Posted 2011-09-14 20:48:29 »

in Slick? setClip on the given Graphics object inside a render method Smiley

never used that.

Like I said, every object/sprite is rendered at absolute location minus camera location

Offline R.D.

Senior Devvie


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #15 - Posted 2011-09-15 00:57:20 »

Me too, at least not for camera issues Wink

(More like split screen stuff or for my map editor)
Offline duce

Senior Newbie





« Reply #16 - Posted 2011-09-15 01:19:44 »

So the rectangle follows the camera, not vice versa?
Offline duce

Senior Newbie





« Reply #17 - Posted 2011-09-15 03:13:45 »

I think I get it now, I was in a completely different mindset. I was focused on the canvas moving around, instead of the objects moving around dynamically to the "camera". Thanks for the tips, I'll see how it works.
Offline gimbal

JGO Knight


Medals: 25



« Reply #18 - Posted 2011-09-19 09:28:28 »

Its easier to visualize if you have a real world example. Remember Warcraft 2? You have the large map and the minimap. On this minimap you see a rectangle which you can move around to see that part of the larger map.

http://www.allvideo.org/pictures/warcraft/warcraft2_screenshot1.jpg

The minimap is your entire world, the 'main game area' is your canvas.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #19 - Posted 2011-09-19 16:51:21 »

The rectangle in the minimap still perpetuates the "camera" idea.  Imagine the minimap rectangle is stuck in the center of the minimap, and the entire map scrolls to fit the visible part within that rectangle.  That's how the camera works: your camera never moves, you simply move the whole world into view.

 Then you will see that it is not the spoon that bends, but yourself Smiley
Offline gimbal

JGO Knight


Medals: 25



« Reply #20 - Posted 2011-09-20 13:33:27 »

The rectangle in the minimap still perpetuates the "camera" idea.  Imagine the minimap rectangle is stuck in the center of the minimap, and the entire map scrolls to fit the visible part within that rectangle.  That's how the camera works: your camera never moves, you simply move the whole world into view.

 Then you will see that it is not the spoon that bends, but yourself Smiley


Yes thats how the OP is currently doing it, right? Translate everything in the entire world. But the idea posed in the thread is to not move the entire world but to move the camera rectangle. The latter matches the minimap example.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #21 - Posted 2011-09-20 17:46:03 »

Another way of thinking about it is you move the minimap rectangle internally, but to actually render things into view you translate (move) it and the world back in the reverse direction so it's back at the center where your fixed unmoving camera lives. 

In that case, the camera, such as it is, is like any other object in the world, except you always render it first and you use the inverse of the normal translation and rotation to get your camera transform on the world.
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!