UI alignment
Elliot

I've been trying to make my ui stick to one side of the screen, regardless of the screen size. I tried using the setAlignment function of SceneObject, but it doesn't seem to do what I want. I must be missing something... how do you do that?

All 2 Comments
Gio

You are right, you have to use setAlignment.

However all it does, is it tells WADE how the object should behave when the screen is resized.

So for example, if you want an object to always be on the top left corner of the screen, you'd do this:

// place object in the top-left cornervar x = (objectWidth - wade.getScreenWidth()) / 2;var y = (objectHeight - wade.getScreenHeight()) / 2;object.setPosition(x, y); // tell WADE that its position is relative to the top-left corner// so it knows where to move it when the screen is resizedobject.setAlignment('left', 'top');

setAlignment has 2 parameters: the first one is for the x axis (and can be 'left', 'right' or 'center') - the second is for the y axis (and can be 'top', 'bottom' or 'center'). If you don't call setAlignment, the default value is 'center' for both.

I hope this helps.

Elliot

It does help, that's exactly what I wanted to do. I thought that setAlignment would move the object to the side of the screen, but I think I see why it's better that it doesn't. This way if I want my object to always be 30px from the left edge for example, I can do that. It all makes sense, thanks a lot.

Post a reply
Add Attachment
Submit Reply
Login to Reply