GML How do I deactivate objects not in my players view?

Discussion in 'Programming' started by mikix, Jul 13, 2019.

  1. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    343
    This does not work


    In player step event:
    Code:
    instance_deactivate_region(view_xport[0]  view_yport[0], view_wport[0], view_hport[0], false, true); //deactiveate all outside view 
    instance_activate_object(obj_Enemy_1_Start_19); //save this object from being deactivated
     
  2. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    17
    I use dnd, but it would look like this is psuedocode...

    Get players view bounds, assuming thos are yoru inputs here.
    Apply to All
    if x < other.view_xport[0] or x > (view_xport[0] + view_wport[0]) or y < view_yport[0] or y > (view_yport[0] + view_hport[0])
    then deactivate

    according to the manual, I am assuming your instance_deactivate_region() should work though.
    Your view variables look valid too, to me.
     
  3. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,589
    port, as in view_xport, refers to the view port, or how the view is being rendered to the screen (or the application surface).
    view, as in view_xview, refers to the view, or which portion of the room the camera sees.

    You're looking for the latter.
     
  4. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    343
    Thank you @Doulos and @TsukaYuriko

    The game runs a lot smoother now! I deactivated everything in the Outside View event.

    But I have a minimap where I have alt + clicked the solid wall all around the tileset walls. I don't see them disappearing and reappearing on the characters view.
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,589
    Tiles are not instances and will not be deactivated by instance deactivation.

    If you want to optimize tile drawing, check out surfaces in the manual - the basic idea for this is to draw all tiles to the surface once, only redrawing the surface if the player leaves the area that is currently drawn to the surface, then only draw the surface from that point on and hiding the tiles. It massively cuts down on the amount of draw calls and should improve performance.
     
  6. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    343
    @TsukaYuriko I solved it with the minimaps script code.

    Code:
    if distance_to_object(obj_Player_Wizard) < 1200
        {
            draw_set_alpha(1)
        }
      
        if distance_to_object(obj_Player_Wizard) > 1200
        {
            draw_set_alpha(0)
        }
    }
     
  7. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,398
    Hmmm, is that still the case in GMS2?
    I mean those tiles are a single draw call... Even a single piece of geometry!
     
  8. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    17
    Not wanting to side topic here, but.
    Are we saying using many small tiles are not efficient?
    Should we just create a smaller number of larger objects that do almost nothing, which we can then enable / disable outside of view?
    or Perhaps I just do not understand your comment @TsukaYuriko ?
     
  9. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,589
    @GMWolf:
    I was discussing this matter in-depth on the old GMC: http://gmc.yoyogames.com/index.php?showtopic=631986

    To which extent this holds true in GMS2 is not something I know or have tested, but you're welcome to test this for yourself and share the results. Since the old view system is being used instead of the camera system, I figured this was about 1.x - on a second thought, it can technically still be used in GMS2, though... so I probably should've clarified that first. My bad.

    @Doulos:
    I'm not talking about big tiles vs. small tiles, I'm talking about tiles vs. surface. The rest is explained in the topic I linked above.
     
  10. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    417
    Changing their alpha don't deactivate them.
     

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