# \[SOLVED\] S4P best movement for the player in the world

**URL:** <https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051>\
**Category:** Libraries\
**Created:** [June 14, 2019, 12:38am UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051 "2019-06-14T00:38:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 14, 2019, 12:38am UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/1 "2019-06-14T00:38:00Z")

</div>

Hey Guys !

I am working on a game. And I have been incorporating S4P and I was thinking what is the best to move the player within the world. Currently I keep the player in the middle of the screen and just used `S4P.moveWorldBy()`. Any better take ons ? Or is this fine ?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 14, 2019, 10:49am UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/2 "2019-06-14T10:49:57Z")

</div>

I have not seen your game but one problem might be disorientation because the world is always moving.

Another approach you might consider is to allow the player to move within a rectangular area that is smaller than the sketch window box but also centred on the sketch window, then only move the world if the player attempts to leave this area.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 14, 2019, 10:53am UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/3 "2019-06-14T10:53:09Z")

</div>

Hey There!

The world is large, players can move freely and the sketch window only gets to see a portion of it. So I am looking for a good camera system. As you said shifting the world will be disorientating especially that there are tiles and enemies. Does S4P encorpora! te any camera system ? If not any take on a library that does ?

Also soon I will feature a demo of the game here ! To receive criticism on how to improve it ! As I plan to release it!

[World](https://discourse.processing.org/uploads/short-url/qvDzijaWfg4OBJsdmdGSaG9s9IR.png)

So that how the world looks like . And I am trying to see what the best way to move the camera then !

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 14, 2019, 12:41pm UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/4 "2019-06-14T12:41:51Z")

</div>

> [@InferNova](#):
>
> The world is large, players can move freely and the sketch window only gets to see a portion of it.

I worked that one out myself 😀

S4P is a 2D sprite system so a camera system would simply decide on where the centre of the viewable area is and the display scale. S4P provides several methods to change this view e.g.

```auto
moveWorldBy(px, py)
moveWorldTo(px, py)
resizeWorld(scale)

```

plus methods to convert between **world** and **display** coordinates.

So although S4P does not have a camera system per se all the core stuff is there to represent a camera. It is unlikely that a 3rd party camera system would integrate as well with S4P.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 14, 2019, 12:51pm UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/5 "2019-06-14T12:51:56Z")

</div>

So I guess I am on the right track ! I guess I am just gonna make a wrap around class for moveWorldBy. Also the .isOnSceeem() works great for only rendering tiles that are seen on the screen I love it. That also fixed the issue from my ControlP5 post!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 14, 2019, 12:58pm UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/6 "2019-06-14T12:58:57Z")

</div>

> [@InferNova](#):
>
> I guess I am just gonna make a wrap around class of moveWorldBy

I am a great fan of object orientated programming so creating a camera class _could be good_ provided there is a real need for the class and its design is based on sound object orientated principles.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 14, 2019, 1:00pm UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/7 "2019-06-14T13:00:18Z")

</div>

There is a need indeed! I will make sure to make a sophisticated one. Before the end of tonight I will showcase what has been done. To receive feedback on improving performance !

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 16, 2019, 3:14pm UTC](https://discourse.processing.org/t/solved-s4p-best-movement-for-the-player-in-the-world/12051/8 "2019-06-16T15:14:01Z")

</div>

Hey so the best method I found was use translate(player posx - width/2 , player posy - height/2)  
As moveWorldBy didn’t work as the game features LAN.
