How to keep the centre of an image in the screen?
This is kind of tough to explain. I'm basically making a sniper game, and the actor is the scope. You're basically looking through the scope to kill enemies. I set the actor to follow the mouse, and thankfully, it does. I then added an image of a scope in the centre of a black image so it can cover the whole scene except of the middle (the scope...). Whats bugging me is, when I move the mouse to the very left of the screen, the right of the screen shows up due to the size of the image. I tried increasing the size of the image but nothing worked. I tried increasing the actors size but nothing worked. I hope you know what i'm trying to say as it is very difficult to explain.
Thanks in advance.
Thanks in advance.
Comments
-drahc
If so, you can do something like this:
Create 4 integer attributes inside the scope Actor:
leftLimit
rightLimit
topLimit
bottomLimit
Set the left and bottom limits to half the width of the scope. Set the right limit to the screen width minus half the width of the scope, and the top limit to the screen height minus half the height of the scope.
Then, also in the scope Actor, use two Constrain Attributes like this:
Constrain Attribute: self.Position.X To: max(self.leftLimit, min(self.rightLimit, game.Mouse.X))
Constrain Attribute: self.Position.Y To: max(self.bottomLimit, min(self.topLimit, game.Mouse.Y))
Make sure to choose all of those attributes from the dropdown menu in the expression editor.
You can play with the limits to set a specific area that the scope must stay within.
Hope this helps!
Joe
I would appreciate it if you can check this game out. I 'am not making an exact copy of this game but I'm making the same kind of scope. Hope this helps and I get a reply soon.
Goldensnypa