0

I'm trying to create a very basic cocos2d program, but the scene only takes up 1/4 of the window starting from bottom left corner to middle of the window.

I tried changing the scene's position with scene.position= x,y but cocos seems to treat the middle of the window as its upper right corner.

import cocos
from cocos.director import director

if __name__ == '__main__':
    director.init(
        fullscreen=False, width=1280, height=800)
    hello_layer = HelloCocos() #Grey ColorLayer and a "Hello" label on it.
    test_scene = cocos.scene.Scene(hello_layer)
    test_scene.position = 0, 600

    director.run(test_scene)

You can see here that the scene doesn't go past the middle of the window. In full screen, there is no problem, and the scene takes up the whole screen. How do I get the scene to take up the whole window? Making it bigger didn't help either, it just goes off the bottom and left edges.

Xzayler
  • 1
  • 3

1 Answers1

1

In cocos, the scene's anchor point is by default (0.5, 0.5). This means that the (0, 0) of scene is at its centre.

When you position your scene at (0, 600), you are saying that the centre of your scene is at (0, 600) of the window (visible region).

Now, I am assuming that your scene's size and window size are both width=1280, height=800. This will make part of the scene go out of the window. Specifically on the top-left side.

Here is a reference image to explain the same

To centre the scene, you might want to position the scene at the centre of the visible area(window) at (640, 400). Or explicitly set its anchor at (0, 0) and set the position at (0, 0).