Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when is Camera.contentPosition used? #11

Closed
wenq1 opened this issue Jan 11, 2017 · 8 comments
Closed

when is Camera.contentPosition used? #11

wenq1 opened this issue Jan 11, 2017 · 8 comments

Comments

@wenq1
Copy link

wenq1 commented Jan 11, 2017

I can see that in SHOW_ALL mode of the camera, contentSize is scaled and contentPosition is set. However upon drawing, is contentPosition taken into account?

Say I have a screen (portrait) of 1200x1920, I set targetContentSize to be (600x400), the content is scaled to 1200x800. When drawing, this 1200x800 rectangle should be centered vertically,shouldn't it? I fail to see where in the engine that process this step.

@elnormous
Copy link
Owner

Content position is set so that you know where the content's left bottom position is in the viewport. It is not being used, because scale modes need only scale factor to be calculated and then applied to the scene.

@wenq1
Copy link
Author

wenq1 commented Jan 12, 2017

So it is the viewport that actually gets centered? I don't see that implemented in the code either ... Maybe I missed it somehow?

@elnormous
Copy link
Owner

This is the line that creates the scaled orthographic matrix: https://github.com/elnormous/ouzel/blob/master/ouzel/scene/Camera.cpp#L91

@wenq1
Copy link
Author

wenq1 commented Jan 12, 2017

I fully understand this orthographic matrix. However when I use the engine, say with an example device screen size of 1200x1920, and targetContentSize of 600x800, the contentScale is correctly set to 2. But when I try to draw a 600x800 sprite at position (0, 0), it is drawn on the bottom left corner of the device screen. I am expecting it being drawn vertically centered on the screen, WITHOUT manually setting the position, hence the question.

@wenq1
Copy link
Author

wenq1 commented Jan 12, 2017

Device: 1200x1920
+------+
|      |
+------+
+sprite|
|------+
|      |
+------+
     

targetContentSize: 600x800
draw sprite of size (600x800) at (0, 0)

Expected
+------+
|      |
+------+
+sprite|
|------+
|      |
+------+


Actual
+------+
|      |
|      |
|      |
+------+
+sprite|
|------+


@elnormous
Copy link
Owner

What scale mode are you using? Can you please post your code somewhere?

@wenq1
Copy link
Author

wenq1 commented Jan 12, 2017

nothing special here. Basically it boils down to



        videoLayer = new Layer ()

        videoCamera        = new Camera ('show-all');
        videoCamera.setTargetContentSize (600, 400);
        videoLayer.addCamera (videoCamera);
        addLayer (videoLayer);

        videoSprite    = new Sprite (600, 400);
        videoNode      = new Node ();
        videoNode.setPosition (0, 0);
        videoNode.addComponent (videoSprite);

        videoLayer.addChild (videoNode);


@wenq1
Copy link
Author

wenq1 commented Jan 13, 2017

Ah.. I see. Ouzel has center of the screen as the origin, whereas I'm assuming the bottom-left corner.. How interesting..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants