• 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!

[SOLVED]Ways to make an area wrapper?

Pfap

Member
I've been trying to come up with a way to make a screen wrapper much like gml's built in function.
Code:
move_wrap(hor, vert, margin);
Except, I want to wrap instances in a defined area on screen. I figured I could just snap the instance to the other side of the screen, but it feels jarring. In the past I've done stuff with a wall_obj at a higher depth that the instance I want to wrap can hide behind before getting snapped, but it feels hacky and in my current project just creates a bit of an eye sore. I'm sure I'll think of something, but does anybody have any suggestions?
 

TheouAegis

Member
Wrapping has always been jarring. One step it's entirely on the right, next step it's entirely on the left. If you want a smooth wrap, you have to have the instances on BOTH sides. This also means collisions would have to be handled on both sides.
 

Pfap

Member
Wrapping has always been jarring. One step it's entirely on the right, next step it's entirely on the left. If you want a smooth wrap, you have to have the instances on BOTH sides. This also means collisions would have to be handled on both sides.
Yes, that's what I have in mind. Like a conveyor belt, but if I have instances on both sides how can I make the ones outside my defined area not visible? Maybe it's impossible, besides using the hiding behind strategically placed walls method.

Edit:
I tried using an
Code:
 if x > my_areas bounds{ visible = false; }
But, it's invisible until all of a sudden it is visble… like you mentioned jarring.
 

TheouAegis

Member
It shouldn't matter if they are visible,they are outside the view. If you were running two instances each, the master instsnce would set the puppet's position. If
On the left half of the view, puppet's position is view width to the right. If on the right half, pupoet's pupoet's position is view width to the left.
 
I would probably use a surface. You'll still need to draw the instance on the left side and right side of the surface as it wraps. The parts of the sprite that are outside the surface won't be drawn. Then draw the surface to the screen.
 

Niels

Member
I did horizontal wrapping for a project once.
I achieved a pretty smooth wrap by setting a trigger on objects where if they were closer to the room edge than a half view, they drawn a clone of themself at their location + room_width (or minus if they were at the right side of the room).
Also the player checked for a collision at the other side of the room when it was a the edged of the room.
Ofcourse this only worked when setting the view in code
 

Neptune

Member
In pseudo terms:
if near edge,
- draw_sprite_part(one side)
- draw_sprite_part(other_side)
else
- draw normally

Once you get that setup, you can easily run secondary collision checks where the "clone" is being drawn, and determine when to actually teleport the instance to the clone's coordinates.

I do NOT recommend using multiple instances.
 

Pfap

Member
I would probably use a surface. You'll still need to draw the instance on the left side and right side of the surface as it wraps. The parts of the sprite that are outside the surface won't be drawn. Then draw the surface to the screen.
That worked perfectly with the camera and view functions.


Create event:
Code:
wrap_surface = -1;

//main camera
view_camera[0] = camera_create_view(0, 0, 432, 768, 0, -1, 5, 5, 0, 0);
//current wrap field 
view_camera[1] = camera_create_view(global.left_x, global.top_y, global.right_x-global.left_x, global.bottom_y-global.top_y, 0, -1, 5, 5, 0, 0);

view_enabled = true;
view_visible[0] = true;
Draw event:

Code:
wrap_surface = surface_create(camera_get_view_width(view_camera[1]), camera_get_view_height(view_camera[1]));
   surface_set_target(wrap_surface);
   
   with (piece_cont)
      {
      var _vx = camera_get_view_x(view_camera[1]);
      var _vy = camera_get_view_y(view_camera[1]);
      draw_sprite(sprite_index, image_index, x - _vx, y - _vy);
   //draw_text(x - _vx, y - _vy,which_one);
   
      }
   surface_reset_target();
   
   
   draw_surface(wrap_surface, global.left_x, global.top_y);


I recently ran into another issue which I will make a separate topic for, involving the buffer surface functions.
 
Top