Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Would like to understand the logic behind constraint objects


I would like to understand's gamesalad's logic behind constraining objects to whatever position I would like. I am making a game that will be universal. So, I understand that you cannot have set positions but positions set on variables that shift depending on the device size. So, I want to know how to center an object, make an object go to the right, left, up and down of a screen. I have been planning around with the framework for a while now trying to understand the logic of how to place objects on screens. So I wanted to know if someone can explain the logic of placing actors where ever you like on screens. Let's say I wanted to know how to place an actor on the right, left, top and bottom of a screen. How would that logic work?


  • pHghostpHghost London, UKPosts: 2,289Member

    You want them to be touching the edge?

    In that case the top would for example be game.Screen.Size.Height - (self.height/2)

    That's the height of the screen and subtract half the height of the actor you are moving. Why? Because if you place it at the height of the screen, that's where the middle of the actor will sit, so you need to move it half of it's height down. Etc.

    You won't be using constrains for this, though. A simple change attribute is enough. Constrains are only for things where you need to check if the actor is in the correct place every single frame. Unless there is any other logic that could be messing with the actor, you're more than safe with a change attribute.

  • raandm17raandm17 Posts: 8Member


    So, I was playing around with the framework. I noticed when I said game.Screen.Size.Height*2 the actor would move to the top of the screen. But, when I change the device size (iPhone 6, iPhone 5 and etc) the actor would stay in the center of the screen.

    In addition, when I did the method you suggested the actor just stayed in the center of the screen regardless of device size.

Sign In or Register to comment.