0 Favourites

[SOLVED]How do I determine visible area?

  • Helo World,

    This next game that I'm gonna be working on would be perfect for using scale outer. However I'm having trouble figuring out how to set up my game based only on the area that the player can actually see on his particular device.

    For example lets say my layout is 640x480(and lets assume everyone can see all of it) and that I have an object(size 30x30, origin at 15x15) that I want to spawn in random locations. Normally I would have some events like:

    1. on start of layout | system scroll to

    x: 320

    y: 240

    2. every x seconds | create object at

    x: random(40,610)

    y: random(40,440)

    So in that scenario I know the starting x/y and the ending x/y of what the player can see. And I know that I have to add 40 to the starting x/y and substract 40 from the ending x/y, that way the object will be created at random positions but will always be fully withing the layout and will have a little space between it and the layout edge.

    However if I use scale outer I would need something like(let's call it visible.area, I don't know what the proper term is):

    1. on start of layout | system scroll to

    x: 320

    y: 240

    2. every x seconds | create object at

    x: random(visible.area.start+40,visible.area.end-40)

    y: random(visible.area.start+40,visible.area.end-40)

    And it's not just for randomly spawned objects, that was just an example, I would olso need to always keep my HUD elements at a certain distance from the visible.area edge, etc. So, in conclusion, how do I make sure that my entire game is always within the part of the layout that the player can actually see on his device?

    Thank you.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • those system expressions will probably do the job

  • K, thank you Fidasx , so viewport means the actual visible part of the layout, correct?

  • yea exactly

  • Ok, thank you Fidasx . Then I guess I can just save the viewport values in some variables on start of layout, and then I can use those variables later for the random positions and stuff.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Depth sorting - almost solved
62 5,167
lucid's avatar
lucid
Unread hot topic
99 10,149
karshinkoff's avatar
karshinkoff
Unread hot topic
0 Favourites
How do I fix this (Solved)
47 1,949
tomi71's avatar
tomi71