1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 how to make a solid surface (physic) without sprite index?

Discussion in 'Programming' started by Bhreno, Nov 6, 2019.

  1. Bhreno

    Bhreno Member

    Joined:
    Oct 5, 2019
    Posts:
    45
    It's possible?
    In my game, obj_ball collides with a "scratch" created by the mouse (a surface), and deflects. However, I can't make this surface solid enough that obj_ball detects any collision with it.
     

    Attached Files:

  2. DullShrimp129

    DullShrimp129 Member

    Joined:
    Feb 18, 2018
    Posts:
    9
    You could use place_meeting()
    If you want a system for deflection you could use this

    if(place_meeting(x,y,object))
    {
    if(direction>=0)
    {
    direction = -direction;
    }
    if(direction<=0)
    {
    direction = direction;
    }
    }
     
    Bhreno likes this.
  3. TailBit

    TailBit Member

    Joined:
    Oct 16, 2019
    Posts:
    56
    use:
    sprite_create_from_surface(index, x, y, w, h, removeback, smooth, xorig, yorig);
    and set it as a object's sprite_index ..

    Just keep in mind that this could cause memory leak if you keep creating sprites without destroying them at some point.
     
    Bhreno likes this.
  4. Bhreno

    Bhreno Member

    Joined:
    Oct 5, 2019
    Posts:
    45
    I did that, but the obj_ball still don't detect any collision with obj_surface.

    The "surface" of obj_surface is created from the mouse click and its codes are:

    IN CREATE:
    Code:
    surface = surface_create(room_width, room_height);
    spr_custom = sprite_create_from_surface (surface, 0, 0, 10, 10, false, false, 5, 5);
    sprite_index = spr_custom;
    mx=0;
    my=0;
    alarm[0]=120;
    IN DESTROY:
    Code:
    surface_free (surface);
    sprite_delete(spr_custom);
    if point_limit == false
    {
    if point < 20
    {
    point +=1;
    }
    }
    IN ALARM [0]
    Code:
    instance_destroy();
    IN STEP EVENT:
    Code:
    mx=mouse_x;
    my=mouse_y;
    IN GLOBAL MOUSE LEFT BUTTOM
    Code:
    surface_set_target(surface);
    draw_set_color(c_black);
    draw_circle(mouse_x,mouse_y,5,false);
    draw_line_width(mouse_x,mouse_y,mx,my, 10);
    sprite_add_from_surface(spr_custom, surface, mouse_x, mouse_y, mx, my, false, false);
    surface_reset_target();
    
    IN DRAW EVENT:
    Code:
    if surface_exists(surface)
    {
    draw_surface(surface, 0, 0);
    } 
    And in the collision with obj_ball, has "instance_destroy".
    The obj_surface is physic e no have sprite (only spr_custom);
     
  5. TailBit

    TailBit Member

    Joined:
    Oct 16, 2019
    Posts:
    56
    You created it when the surface was empty .. so ofc there won't be any collisions, delete sprite and create a updated one after drawing is done:

    in global mouse left release, or at the end of the current mouse event if you want it to happen right away..
    Code:
    sprite_delete(sprite_index);
    sprite_index = sprite_create_from_surface (surface, 0, 0, 10, 10, false, false, 5, 5);
    spr_custom = sprite_index;
    Any reason you made the spr_custom? Didn't deleting it directly from sprite_index work?
     
    Bhreno likes this.
  6. Bhreno

    Bhreno Member

    Joined:
    Oct 5, 2019
    Posts:
    45
    I did this, yet the surface remains untouched by obj_ball. She is not solid for anything. :(
     
  7. Catastrophe

    Catastrophe Member

    Joined:
    Sep 22, 2019
    Posts:
    103
    The obj_surface is physic e no have sprite (only spr_custom);

    ^by "physics e" you don't mean physics enabled do you? Because a sprite index isn't going to do anything for physics I think, you'll need a fixture. Not that you'd want physics enabled probably, I just don't understand what is being said here and wanted to clarify

    What is the collision code for the ball/surface, like what actually is used to detect collisions (place_meeting, collision event, etc)?

    I would also not draw your surface to the screen after you have set your sprite_index, just to make sure have correctly attached the actual sprite to the object. If you don't see anything, your obj_surface did not transfer the sprite correctly.



    Additionally, if you read the manual on sprite_create_from_surface it's going to create your bounding box for collisions automatically. Since you have a curve you will want to use sprite_collision_mask and set it to precise collisions

    Finally, google "destructible terrain tutorials game maker" and these should give you general guidance on this method, you might figure things out yourself without additional help if you check those out. Technically it's the opposite since you're adding, but the same principles will apply

    Edit: oh duh, you need draw_self() in your draw event
     
    Last edited: Nov 10, 2019 at 10:30 AM

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice