• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Inventory screen "sliding"

I've had this issue for a while now but just kind of looked past it. Well, now I'm ready to fix it.

So, I have an inventory screen which is supposed to pop up dead center on the screen every time I open it. I have this code to do that:

Code:
x = camera_get_view_x(view_camera[0]) + 160;
y = camera_get_view_y(view_camera[0])+ 120;
It pops up in the center of the screen just fine ONLY IF:

a.)The player is at the edge of the screen, so the view isn't moving
b.)The player is standing still

When the player opens the inventory, they are unable to move until they close it (that's how I want it).
Now, the issue is that, when the player tries to open the inventory while they're moving (and the view is following them), then the player will stand still as planned, but the inventory screen will pop up slightly off center and then slide to the center (this takes about a half second).

My code for the view object that follows the player:
Code:
x += (obj_player.x - x) * .6 ;
y += (obj_player.y - y) * .6 ;
Now, it's worth noting that if I switch the object following in the room editor from obj_view to obj_player, the inventory doesn't slide when the player is moving, which is what I want. But, I wanted better view movement, which is why I wanted the camera to follow obj_view instead.

Any help?
 
D

deem93

Guest
Personally I use display_get_width/height instead of camera_get_view_x/y because of some problems I had with the latter. If you want something to appear dead center, you simply use display_get_width/height and divide it by 2. See if it helps.
 
Personally I use display_get_width/height instead of camera_get_view_x/y because of some problems I had with the latter. If you want something to appear dead center, you simply use display_get_width/height and divide it by 2. See if it helps.
I was wanting the inventory screen to pop up wherever the player is in the room dead center, no matter where they go to. I tried your suggestion and it just makes the inventory be at one spot constantly and not follow the player.
 
E

Edwin

Guest
I was wanting the inventory screen to pop up wherever the player is in the room dead center, no matter where they go to. I tried your suggestion and it just makes the inventory be at one spot constantly and not follow the player.
That your inventory object is creating outside the view is because it set the position every step so you can try setting code to End Step Event instead of Step Event or put the same code in Create event.
 
D

deem93

Guest
Could you describe better how you used the code?
In the meantime here is my solution that works for me:
In the Create event:
positionX = display_get_width() / 2;
positionY = display_get_height() / 2;

In the Draw GUI event for drawing text and sprites for the inventory:
draw_sprite(sprite, subimage, positionX, positionY);
draw_text(positionX, positionY, string);
 
My view port is 640 x 480, with my camera view being 320 x 240. I have the camera following the obj_view, which in turn follows the player.

In the obj_view, I have this code for following the player:

Code:
x += (obj_player.phy_position_x - x)*6;
y += (obj_player.phy_position_y - y)*6;
For the actual inventory screen, I have this code to make it pop dead center wherever the view currently is:
Code:
x = camera_get_view_x(view_camera[0]) + 160;
y = camera_get_view_y(view_camera[0])+ 120;
This works fine, unless the player is moving and then they open the inventory because the view is still following the player and hasn't 100% reached them yet, which causes the inventory to slide into position with a slight delay. This doesn't happen if I have the camera following the player instead, but I don't want that.

The way I have it is, the obj_view isn't directly on top of the player the entire time, it lags behind slightly for better camera movement.
 
Top