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

Get help using Construct 2

Post » Wed Apr 23, 2014 1:56 am

@vitorfgd, that is a very complicated subject and you need to be sure of exactly what it is that you want to achieve.

1. Do you want the sprite to take up exactly the number of pixels on the screen irrespective of screen resolution? For example, a 128x128 sprite will look ok on an 800x480 screen but it would look really small on a full HD 1920x1080 screen - and the apparent difference in size would be very striking if the screen dimensions were about the same.
2. Do you want the sprite to take up the same proportion of the viewable screen length/width irrespective of screen resolution or aspect ratio? C2 handles this option very well with its Scale Outer scaling option (and the others, but they are less on mobile usable IMO).

The common advice is to draw your game for the largest aspect ratio you can expect (16:9 or 16:10) and then ensure that your background fits smaller aspect ratios to good effect. There are some great tutorials and threads on this, so do a quick search and have a look through. It's not a decision you can just glibly ignore at the start and then hope to fix later in your development. It also depends on your export target - I understand that C2 does scaling very well so, providing the sprites have the detail, you could draw all of your sprites and layout for 800x480 for example, with each sprite drawn at 1/2 scale, so that if there is any upscaling to be done (full HD / retina screen) then the upscale of your sprites can be done by adding that detail rather than by interpolating pixels. Again, plenty of tutorials ect will cover this better than I can. Personally I have scaled my last few apps to a middle of the road aspect ratio that is better suited for iOS - something like 960x640 or 1136x640 - both are ok for android and iOS and the scale outer can make some exports look longer and some look wider, but I'm personally happy with the average appearance. Whatever works for you...
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Wed Apr 23, 2014 2:03 am

I suppose I didn't answer your question exactly! Looking at my list above, if you want to achieve option 1 then you need to obtain the canvas size and scale your sprites so that they will appear at 1:1 resolution on screen, which means they will need to be scaled in the layout at run time according to the screen resolution - because C2 will try and then scale them so they appear in true proportion to the layout on screen.

For example, let's say you have a 64x64 sprite that you want to have rendered as 64 pixels on screen. If your original layout is 640x640 then C2 will try and draw the sprite so it appears to be 1/10 the width/height of the screen. If the screen resolution is 1280x1280 then you would need to scale the sprite to 1/2 its width/height at run time so C2 would then draw it to appear 1/20 the screen size - which would still be 64x64. Add in the complication of different aspect ratios and you'll begin to see that this is not a good place to go - because you haven't even started you game mechanics yet!

I would advise steering clear of this to begin with and I can't think of many game options where this would be an attractive proposition (there are some, though...).
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Wed Apr 23, 2014 2:45 am

@Colludium Explaining better, in my problem, I have 4 transparent objects in which each will be positioned on the edges (top, bottom, left, right) screen. With the solution you taught me previously, and which by the way works excellently, I can determine that the object reallocate according to the window size, but it will eventually become smaller than her, because its size does not change.
I would like to change its size according to the size of the window (in this case the size of the smartphone).
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Wed Apr 23, 2014 11:02 am

Ah OK - you want the object to fill the screen:

Set object.Width to ViewportRight("HUD") - ViewportLeft("HUD") and do similar to the object's height, assuming it's on the HUD layer and depending on whether it's width or height you're interested in.

Hope that's what you're after?
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Wed Apr 23, 2014 12:10 pm

Yes, it's exactly that I'm talking about. But, when i need to set height I feel lost. How i could do that with height?
I tried some ways, but the object took disproportionate to the size I wanted (the width worked normal only for objects that I wanted to change the height).
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Wed Apr 23, 2014 1:52 pm

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.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Wed Apr 23, 2014 2:13 pm

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.
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Wed Apr 23, 2014 2:23 pm

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.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Wed Apr 23, 2014 4:00 pm

@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.
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Wed Apr 23, 2014 4:04 pm

I'd just be guessing - it would be better if you could post a capx example if possible.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Previous

Return to How do I....?

Who is online

Users browsing this forum: apalm1341, blissfulwizard and 17 guests