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

Legacy GM Moving Surfaces?

Hey guys,

I'm trying to create a destructible terrain that a drill can drill through. Initially I was using objects to fill the screen and then get destroyed, but that is obviously a memory hog and also didn't look great. So I've moved onto surfaces (not even really sure if this is the best way to go about it, but it certainly runs faster than objects).

I'm creating an 'infinite' terrain by having a room that is the size of my game screen (right now 480 x 960) with a view enabled and then simply having the view follow the falling drill through this code in the Step event:

Code:
view_yview[0] = round(y-(view_hview[0]/2));
The drill just uses basic gravity to fall. Then I'm drawing a rectangle the size of the view onto a surface, having that surface be drawn following the view_xview and view_yview, and then having the drill subtract a section where ever it is through a subtraction blend mode.

obj_dirtdraw Draw Event:
Code:
if (surface_exists(surface)) {
    draw_surface(surface,view_xview[0],view_yview[0]);
}
else {
    surface = surface_create(view_wview[0],view_hview[0]);
    surface_set_target(surface);
   
    draw_set_color(make_color_rgb(118,84,50));
    draw_rectangle(view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0],0)
   
    surface_reset_target();
}
obj_drill Draw Event:
Code:
if (surface_exists(obj_dirtdraw.surface)) {
    surface_set_target(obj_dirtdraw.surface);
   
    draw_set_blend_mode(bm_subtract);
    draw_set_color(c_black);
    draw_sprite(spr_destruct,0,x,y);
    draw_set_blend_mode(bm_normal);
   
    surface_reset_target();
    draw_self();
}
draw_text(x,y-10,"Spd: "+string(vspeed));
This is my first real foray into using surfaces and it's not working as I expected. Instead of the surface 'following' the drill, the surface is acting as though the drill is actually moving down and exiting the bottom of the screen, while the drill itself is still being followed by the view. If that sounds vaguely confusing, here's a youtube link to what I'm talking about (about halfway through the vid I restart the game so you can see the problem in action):

You can clearly see the drill is actually moving down, with a vspeed of 10.10, it's obviously being followed by the view, yet the drill destruction moves down and off the screen.

Any help would be greatly appreciated.
 
I

icuurd12b42

Guest
the surface is the size of the view
you draw at room y on the surface which is say 720 tall. causing the surface to have a punch through line from y up to the point where y is bigger than 720. that is the initial line you see. that is the first problem.

you have to draw at y-view_yview on the surface to remap the position to the surface.

the second problem is that your surface is following the view... so it's "falling" with the drill that is why at one point it looks like you drill is simply in an already dug hole. you would need to always draw the surface at the same position and not draw it view relative.... OR you would need to scroll the surface content up at the same speed the drill is falling down if you want to keep it view relative. you can do this copying the content to a temp surface, re-clearing the surface with the color, apply the digging for that frame, then draw from the temp surface, scrolled up a bit, copying the old content over the new one.
 
Top