How to set the player at screen center all the time?

105 views
Skip to first unread message

Dlean Jeans

unread,
Oct 2, 2015, 7:11:19 AM10/2/15
to haxef...@googlegroups.com
My game is a side scroller. The player only moves along the x-axis. It's something like a dodging game. I want the player to be at the screen center at anytime in the game and I can't find any proper way to do this or any tutorial.

UPDATE: I think I lied to you about the "at anytime". It's actually "at anytime unless the camera reaches the bound" which means the player will be allowed to leave the screen center when the camera reaches the bound so he can be anywhere on the x-axis inside the bound.
And also, the player only need to be at the screen center X.
Message has been deleted

Seb Jones

unread,
Oct 2, 2015, 3:13:37 PM10/2/15
to HaxeFlixel
To make the camera follow the player:

FlxG.camera.follow(player);

To add boundaries to the camera, thus only allowing movement on the x axis:

FlxG.camera.setBounds(0, 0, boundWidth, FlxG.height);

Dlean Jeans

unread,
Oct 3, 2015, 12:46:02 AM10/3/15
to haxef...@googlegroups.com
It actually works.
The camera was following like this:
        FlxG.camera.follow(player, FlxCamera.STYLE_TOPDOWN);

And I removed the style and it's working just like I want to.
Reply all
Reply to author
Forward
0 new messages