[SOLVED] How to find center of viewport, not layout center?

  • I noticed that "abs(ViewportLeft(0)+ViewportRight(0)/2" places an object in the middle of the Viewport. This is fine if you scroll to the middle of your game at the start of the layout to work for various screen sizes. However, I noticed that this calculation is not the viewable area, but the center of the layout width.

    Does anyone know how to place an object in the center of the viewable area? For example, a tall phone screen should see this object in the center as well as someone on a tablet - even if the viewable area is scrolled to the left or to the way right when spawning this new object.

  • Haven't confirmed but (viewportleft+viewportright)/2 sounds like it should give you the middle of the viewport regardless of where on the layout you are. Even when you are parallaxes, as long as you place the object on the same layer as you are getting the viewport numbers from it should work fine.

    You can try viewportleft+(originalwindowwidth/2) as well.

  • Tested (viewportleft+viewportright)/2 and it still doesn't give you the middle of viewport even if it's on the same layer. It's sometimes more left and sometimes more right depending on where my player is.

    However, your other method of, "viewportleft+(originalwindowwidth/2)" actually worked! Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think its wasting

    How do you mean?

  • > I think its wasting

    >

    How do you mean?

    Ignore him jook00. I suspect spam bot.

  • zenox98 Thanks!

    Nice site BTW for duckduckgo. Like the illustrations and concept of not tracking personal data! Did you work with a team? Sorry, couldn't private message you for some reason.

  • zenox98 Thanks!

    Nice site BTW for duckduckgo. Like the illustrations and concept of not tracking personal data! Did you work with a team? Sorry, couldn't private message you for some reason.

    duckduckgo is nothing to do with me - it's just a Google alternative, and I don't trust Google :/

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)