How do I set an object's position to the borders?

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Imagine that the Viewport returns the coordinates of the left/right/top/bottom of the visible screen area for the layer that you specify. Subtracting the top coordinate from the bottom coordinate will give you the height of the viewable area in pixels... Have a look at Tutorial: Supporting Multiple Screen Sizes.

    If all of that still seems difficult to grasp I suggest that you press on to looking at other areas of C2 and then come back to it - some of the concepts can be difficult to grasp at first but exposure and practice will help you get used to them. You can always manually make your sprites bigger than the likely screen height/width - if they are transparent then it won't matter that they are distorted.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I understand, I actually got the result wanted for my game using your instructions (thanks again), and worked very well in a browser (therefore only in pc). Unfortunately when I run the test on my smartphone is not as if these commands had not been recognized.

    I mean the resize command, eg (set width to ViewportRight (HUD) - ViewportLeft (HUD)).

    Or another example (set position / / x: ViewportLeft (HUD) y: ViewportTop (HUD) - 33.

    They simply did not work.

    Can explain me why?

    Ps: I have used Cocoonjs and Intel XDK to export.

  • You need to add inverted commas so the command looks like ViewportRight ("HUD") - otherwise it looks for a value of HUD variable, which will probably return zero and so give you coordinates for layer zero instead.

  • Colludium , Well, in my project I'm using the numbers of layers, because I thought that would be correct (after all, the way it was, ran perfectly on the pc browser). I'll try what you said, and I will use the names of the layers, to see if the problem resolves.

    Any other idea what might be causing this problem? After all, which would run correctly in the browser and not on your smartphone? Only used a native command of construct 2.

  • I'd just be guessing - it would be better if you could post a capx example if possible.

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