Optimisation Tips | GameMaker Studio 2

Поделиться
HTML-код
  • Опубликовано: 12 ноя 2024

Комментарии • 116

  • @FriendlyCosmonaut
    @FriendlyCosmonaut  6 лет назад +37

    Shoutout to Ariak for his feedback as I was making the video! Thank you :)!

    • @BeLozeyFoShowzey
      @BeLozeyFoShowzey 3 года назад +2

      Thank you for all of the help you've provided me along my GMS journey. This video especially has improved my workflow and game as a whole. I'd love a sequel to this video if there are any more tips you could share.

  • @MadPropzBaller
    @MadPropzBaller 6 лет назад +93

    The quality of your videos is incredible.

  • @dayf722
    @dayf722 6 лет назад +40

    holy cats, I did not realize a function call in a for loop would check every single time. You just gave my game a pretty significant, easy performance boost!

    • @DanielLiljeberg
      @DanielLiljeberg 5 лет назад

      Ofc it does :)... There would be no way for the interpreter to know if the return value of your function would be the same every time so the function call has to take place. If you have a function call in the assignement part
      for(var i = getMyValue()
      then it will only get called once though since the assignment only happens once.

  • @GunnarClovis
    @GunnarClovis 6 лет назад +18

    By far the best Game Maker video I've ever seen. Great content and presentation. Narrated very well, great subtle video effects and snappy editing, coloring and presentation of the code is great, analogies are clever, just absolutely fantastic.

  • @Underdrummer
    @Underdrummer 6 месяцев назад +1

    Super helpful 6 years later! Thank you!

  • @SGTIvan921
    @SGTIvan921 Год назад +1

    1:25 Common performance sinks: drawing sprites, collisions, amount of objects
    1:53 Run the profiler if you are having performance issues
    2:16 We want the fps shown to be as high as possible when in debug mode
    2:41 What we can see in the profiler
    3:31 Demo: increasing the number of instances in the room
    4:35 Demo: adding collision checks
    5:00 Optimisation Tip: instead of the bullet checking for collision with player, check a player's collision with a bullet instead. (100 checks vs 1)
    5:37 Collision functions' limitations (like place_meeting and instance_place)
    5:54 The limitations generally shouldn't be a problem if 3 bullets are seemingly hitting at the same time, since they may be processed in each step separately which is imperceptible to the player
    6:03 Optimisation Tip: check collisions with tiles instead of collision objects, break a game up to a grid that stores whether a particular place is free or not and check that grid if you want to move
    6:25 Demo: adding a view, instance deactivation is very expensive
    7:08 A few functions to use for deactivation
    7:40 Tip: you could put all the instances that can deactivate in one layer while your important ones in another layer
    8:10 Tip: you could make a parent object
    8:40 Those functions are expensive and do not need to be used every step
    9:00 Changing the instance deactivation to be done every second instead
    9:21 On vertex batches
    10:06 What breaks them (Changing blend modes, drawing surfaces, submitting vertex buffers, using shaders, drawing primitives (draw rectangle, draw circle, etc. - better to draw a one pixel sprite, then stretch it), texture swaps)
    10:40 Changing blend mode tip: avoid placing this function in every object, as that will break the vertex batch every time
    11:11 Solution: make a parent then check it on the parent, and also remember to untick their visible check or leave a comment in their draw event
    11:45 Texture swaps
    12:11 What is a texture swap?
    13:03 A way to put your stuff into one texture: manually assign your sprites to texture groups
    13:22 Example: if a certain room is going to use a subset of sprites, then you can assign them to one texture
    13:54 Micro-optimisations
    14:03 Avoid: repeated function calls (e.g. keyboard_check(vk_right) can be just saved into a local variable [in the step event] then reused)
    14:30 Avoid: repeat unnecessary function calls (e.g. a for loop - save the array_length into a local variable to get that value once)
    15:16 Helpful uses of local variables
    15:25 Addressing other instances: using dot operators can be costly
    16:07 Example given: removing the need to use other.[something], and instead replacing it with a local variable. This means we no longer have to jump to the instance. The local variable is already local in scope and can be accessed anywhere within the event, whereas the max_health is an instance variable and would previously require that you do other.max_health. Local variable var mhealth = max_health would no longer necessitate the need for that. (my_health = other.max_health VS my_health = _m_health --> latter is more efficient)
    17:36 Summary: use profiler, deactivate instances outside of view, reduce collisions, reduce batch breaks & texture swaps, don't repeat function calls, minimise jumps between instances by using local variables
    18:00 There are more ways to optimise
    18:08 Performance is not the ultimate thing, and sometimes readability and simplicity of code is far more important than removing a few nanoseconds off.

  • @drothstomp
    @drothstomp 6 лет назад +27

    I would love to see this video on the start page for gms2. This info is invaluable for beginners, I especially liked the for loop optimization with regards to calling the array size check for each iteration. I have seen tons of example code out there with this same mistake, and it's extremely costly. Awesome work, your tutorials are so impressive, keep it up! =)

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +6

      Cheers! I think it often pops up even in tutorials because it's a level of abstraction beginners may not understand. And even in stuff like create events, having the function in the loop isn't going to be a big deal because it's just going to effect 1 frame. Definitely can be costly if it's constantly running in a step event though!
      Thank you :)!

    • @jennjennjenn61992
      @jennjennjenn61992 Год назад

      people have to have a journey.. not everything can be placed in front of everyone's face. you found this tutorial.. be happy. spread the word. :)

  • @igorthelight
    @igorthelight 6 лет назад +10

    Very helpful video!
    Small tip: you can see how texture page will look like with current settings! Go to Options -> Windows -> Graphics -> Push "Preview" button.

  • @davidblack6792
    @davidblack6792 4 года назад +2

    This needs a sequel with even more tips. Excellent video!!!

  • @corpsenia8622
    @corpsenia8622 10 месяцев назад

    Fine tips! After watching this video, I implemented in my game the function of disabling instances that do not appear on the screen and defined groups for each sprite in texture group and it really made the game faster! Thank you very much for your knowledge, my master! You helped improve the game Corpsenia

  • @JAMPLEYDEV
    @JAMPLEYDEV 6 месяцев назад

    Thank you, One of my games that has had awful performance in HTML for months, works perfectly thanks to your optimization tips.

  • @gustavoberwanger1412
    @gustavoberwanger1412 2 года назад

    very precise solutions for advanced problems. Thanks for the amazing tips!

  • @Miaut236
    @Miaut236 Год назад

    Thank you, this is a very good explanation, every explanation was enetrtaining and informative, I didn't feel the need to fast forward anything. I'm always a bit hesitant to run the profiler, but this makes it look far less intimidating. Thank you again.

  • @giu0014
    @giu0014 Год назад

    Great video! I am thankful for people like you that make it possible for many to better themselves as game developers

  • @thomasrosebrough9062
    @thomasrosebrough9062 3 года назад +1

    Your videos are so straightforward and helpful, I hope you decide to make videos again in the future.

  • @williamhauff5667
    @williamhauff5667 11 месяцев назад

    Thank you! Just starting out learning game dev, this video has been a great help to me. Hopefully you keep posting content and deving!

  • @tonybrice7942
    @tonybrice7942 4 года назад

    Holy crap. Local variable scope had never even occured to me. Amazing what you learn when you watch random video's between coding sessions. FriendlyCosmonaut marry me !!!!

  • @Geig3r
    @Geig3r 6 лет назад +4

    If I could give you 10 thumbs up I would have. You're a natural. Thank you.

  • @kimberlyshirley7823
    @kimberlyshirley7823 4 года назад

    I really need to thank you for your message near the end. I often struggle with perfectionism, to the point that I try to fix problems that don't exist and get stuck in a loop of "this isn't good enough, do it again". I'm going to try my best to just make the game, while also keeping in mind these optimization tips when necessary.

  • @antonarset
    @antonarset 6 лет назад

    I found this tutorial accidentally... One of the best tutorials I have ever saw, not only for GM!

  • @northrain0462
    @northrain0462 6 лет назад +11

    I feel pretty ashamed but... I've been programming in GMS for a lot of years and for all this time I didn't know the thing about local variables' scope. Better late than ever, I guess :D.
    I wonder if there will be other "Optimisation Tips" videos in the future, or at least I hope so..!
    Thanks for the lesson!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +12

      Haha don't worry at all, I remember it being a real eye-opener when I learned about it! There is actually quite a few more topics that could be covered on Optimisation, so a future vid is definitely on the table :)

  • @OneHewMan
    @OneHewMan 6 лет назад +1

    I wish I had seen this video when I started GML a month ago. Luckily it's still early so I can still implement many of these tips into my current project. Thank you!

  • @Khud0
    @Khud0 4 года назад

    I found a couple of amazing small tricks that helped my game to achieve better performance on PS Vita. For example, it was counter-intuitive to me that primitive objects are worse than sprites.Thank you very much! :)

  • @olcaptainahab
    @olcaptainahab 3 года назад

    I love your videos, they're so incredibly clear, well-made, and easy to understand. Thank you.

  • @nicolasdelattre8833
    @nicolasdelattre8833 5 лет назад

    I just wanted to thank for all your tutorials. They're incredibly usefull and well structured.

  • @OxyTJ
    @OxyTJ 6 лет назад

    Very well done, I came across this video while looking up videos on Source Control with GMS2. Glad I found it, keep up the great work!

  • @jamesblackwell4749
    @jamesblackwell4749 6 лет назад +1

    I know this video is about optimisation, and I'll absolutely be looking over my code to improve it after I've got more of the game ironed out, but it makes my mind feel greater at ease to hear that messy code is normal and that you shouldn't focus on optimisation at first, especially as a beginner. I'm very new to properly coding things and I'm constantly worried that I'm doing stuff badly, it helps to know that it's normal, and it helps even more to get tips about how to clean it up after I'm done with it

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +1

      I'm really glad to hear this - this is precisely right. When you're starting out, it's FAR more important for you to just learn, experiment, make progress in your projects, and have fun with your coding. The early stages are where most people quit, and it can be hard enough sustaining the motivation/determination for starting something new without being overwhelmed with the thought that you're "not doing it right". Just don't stop programming and learning, and you'll make progress :)

  • @DitheryStudios
    @DitheryStudios 4 года назад

    That deactivate instances line really fixed everything! I have spent multiple hours putting all tiles (which are objects) for all "sub rooms" in my main room... Ended up not running at all when I tried to load the game. I have a few seconds so everything can "Auto-Tile" where it lags out, but after that it runs perfectly!!!

  • @coleowing
    @coleowing 2 года назад

    I've often wondered how that debug overlay was turned on. Good tips.

  • @gdomjan83
    @gdomjan83 6 лет назад

    Thank you, this is one of the most helpful GMS2 tutorial video I've seen in a long time.

  • @mst3ksanta
    @mst3ksanta 3 года назад

    Thanks love all your videos, they are a big help and you go into a good level of detail in them.

  • @DriftyG
    @DriftyG 5 лет назад +1

    Fantastic tutorial, good work.

  • @JoshuaEfron
    @JoshuaEfron Год назад

    This is a fantastic video. Thank you.

  • @romaingauthier2653
    @romaingauthier2653 5 лет назад

    Delightful in depth video! Well done, and thank you.

  • @chuuuuuuuck
    @chuuuuuuuck 5 лет назад

    holy shit this video is amazing. i had no idea that local variables dont need the other. in order to call them. thank you so much

  • @DayumAli
    @DayumAli 4 года назад +1

    These videos are so well made, and surely take a lot of time; I just had to leave a comment. Great job, really. Liked and subbed.

  • @beefknuckles
    @beefknuckles 6 лет назад

    Thanks a ton for this video. I'm new to Game maker and this is invaluable information!

  • @NeverduskX
    @NeverduskX 6 лет назад +1

    I would love to see more stuff on optimization, if there are still more major/general tips to give.

  • @WangleLine
    @WangleLine 3 года назад

    Your videos are so incredibly helpful, thank you so much for all of this

  • @jacksonrobbins2288
    @jacksonrobbins2288 2 года назад

    Great video, I had no idea about the texture groups. The thousands of green dots could have been handled with particles which should have netted a considerable performance jump, especially at such a scale

  • @porkwoofles3909
    @porkwoofles3909 4 года назад

    Wow, exceptional video.

  • @MultiMarcsOfficialChannel
    @MultiMarcsOfficialChannel 6 лет назад +1

    This is amaznig! Thank you so much for this information and tips!

  • @alvin_row
    @alvin_row 3 года назад

    I didn't know that about the scope of local variables, so when I needed to use a local variable inside of a with I actually converted that local variable into a regular variable just to use the "other" keyword lol.

  • @nuclearbeeberman
    @nuclearbeeberman 3 года назад

    as always this is worth gold :). thanks a lot and keep up the awesome work

  • @DanielLiljeberg
    @DanielLiljeberg 5 лет назад

    Does Game Maker have any good support for running things in multiple threads? Or is basically everything run on a single thread?
    @16:50: "other"causes a "jump"? What is a jump in Game Maker? other.x should ideally only refer to a given memory location and you should be able to access and read that as fast as any other memory address. So this leads me to wonder how "objects" are handled in Game Maker and what overhead they add.

  • @azelwkr3841
    @azelwkr3841 2 года назад

    This was a great help, thanks !

  • @Hiting707
    @Hiting707 10 месяцев назад

    Amazing video, it helped me a lot!!

  • @paxcallow
    @paxcallow 4 года назад

    thank you! as a newbie, this is great!

  • @kennethmkline23
    @kennethmkline23 6 лет назад

    Love your videos! I might need to binge-watch these vids this weekend :)

  • @joshcrackedboooi2392
    @joshcrackedboooi2392 Год назад

    for me i suspect my problem is im using still high quality images and animations from pre rendered 3d stuff and i can not figure out how to lower the images file sizes without loosing quality

  • @christopherrisewick4240
    @christopherrisewick4240 5 лет назад +1

    Haha! We use those asteroid assets in my programming class.
    Thanks for the video. :)

  • @andycarr3711
    @andycarr3711 5 лет назад

    Useful and to the point. Cheers.

  • @Bricksalive
    @Bricksalive 6 лет назад +1

    Hi. Great video, lots of useful tips I didnt know about. I have a question: i am working on a survival game and I am wondering, is it more efficient to have a completely separate object for each type of animal/resource or to have a single object with a different state for each animal/resource (using a switch statement)?
    Thanks

  • @MaximoGonzalez-sy4yz
    @MaximoGonzalez-sy4yz Год назад

    Nice video thanks, I learned a lot.

  • @GameDevYal
    @GameDevYal Год назад

    I find it kinda amusing that the microoptimization to break the array_length call out of the for loop still has the -1 in there, so you're still gonna do that math operation every iteration of the loop :P (Compile-time constant expressions are simplified to a single constant but since this is runtime it probably won't get saved by the compiler)
    Goes to show how there's always room to improve things further, "perfect is the enemy of good" and so on, I guess.

  • @junepaik2386
    @junepaik2386 2 года назад

    At 15:18 there is a tiny little mistake: alength already is the array length minus one but in the loop you subtract another time.

  • @darthania
    @darthania 5 лет назад

    Oh my god this is incredible, THANKS!

  • @ГендальфБелый-ш7р
    @ГендальфБелый-ш7р 6 лет назад +4

    You are best ! (Hello from Russia)

  • @kirthalion4726
    @kirthalion4726 5 лет назад

    Your tutorials are super helpful!

  • @DrTomb
    @DrTomb 5 лет назад

    Thank you for the video, It was very helpful.

  • @doctorzoidberg3000
    @doctorzoidberg3000 6 лет назад

    Very well explained! Thank you so much for make this video. :)

  • @RJiiFin
    @RJiiFin 5 лет назад

    Are you sure your indexing is correct around the 14:54 mark? To me it seems you're off by 1 in the first case, and by two in the optimised case? Have you also actually profiled the getting of the array length has an effect? Seems like an optimisation that most compilers would make automatically (although I haven't ever used GM)

    • @jennjennjenn61992
      @jennjennjenn61992 Год назад

      you haven't used gamemaker but you're questioning her obvious mastering of the language after watching 15 minutes of a video for an application you don't even use? sounds fishy mate

  • @funkyb6598
    @funkyb6598 6 лет назад

    This is great, thank you! Thumbs up.

  • @mastergrey9082
    @mastergrey9082 6 лет назад

    I agree so much with your say on optimization it has been the most develop breaking thing in me trying to make this sandbox game of mines.Still im trying to find a way to chunk ds_grids.

  • @DrTomb
    @DrTomb 5 лет назад

    do global variables count as switching between instances, or is there a reason we don't use so many global variables?

  • @BradGqunit
    @BradGqunit 6 лет назад

    Do you find it more efficient to have a "drawing controller" that handles all your games' draw events or is it just easier to organize & decide whats get drawn when. Or both even?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +2

      It depends (a LOT). I would say if your draw events are relatively simplistic it would be better to have them in the separate objects. However if you're applying lots of effects/shaders/playing with surfaces/have built your own way of rendering everything, it could be better to have it from a controller. It's often a matter of scale, too - if you graph two methods along an increasing scale of objects, you may find one is more efficient with fewer objects, and then at >100 objects the other method is more efficient.
      I wouldn't worry too much, and opt for what makes more sense to organise/program. (Unless you have performance issues or are planning on building a MMORPG!)

  • @GabbMonkey
    @GabbMonkey 6 лет назад +1

    Great, as always ♥

  • @rlindstrom3
    @rlindstrom3 6 лет назад

    Quick question for you. You had an example of using the var function to assign a keyboard command and then have the code call up that variable instead of constantly using the keyboard_check function. When I start creating a game I have certain scripts that I have set up and use, one of them is a script where I have variables set up for each keyboard command and then use that script in any event that needs to check for those commands.
    By using that script over and over, is it basically doing the same thing as constantly checking for a specific function, or does it optimize the code a little?
    Great video btw.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад

      Yes, whenever you would call that script, it would run all of those functions. If you have a lot of objects running that script, an alternative could be to have ONE object run those checks and save them in global variables (make sure this object is running its events BEFORE all of the others - a way to do this is to put the code in the "begin step" event). Then, have the other objects access those variables. If it's only a couple objects running the script, I wouldn't worry too much about it!

  • @zaizicat
    @zaizicat 6 лет назад

    helpful,clear tutorial.thanks a lot!!!!!

  • @yulaserio
    @yulaserio 3 года назад

    Thank you so much!

  • @calebob1990
    @calebob1990 6 лет назад

    Hello, thanks for this informative video! Did you source most of this information from the manual? Or more specifically how did you identify all these issues and their fixes?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +1

      Cheers! A lot of the info about performance sinks (deactivating objects, reducing texture swaps/batch breaks, collisions) has been well known and discussed for years in the GM community (though a lot of these issues/fixes can be applicable across game engines). I've internalised and read a lot of forum posts and blog posts, eg. here www.yoyogames.com/search/results?utf8=%E2%9C%93&query=optimisation, though note some of them may be a little out of date. The GameMaker Discord and reddit can also be really great places to find discussion on performance/optimisation, with a lot of users contributing "tests" (such as for comparing the speed of different functions or data structures).
      The solutions such as deactivating instances, reducing texture batches/swaps, minimising the use of expensive functions if necessary, as well as a lot of the tips for coding "best practises" are also quite widespread. It would be difficult to attribute them to any one person as I see a lot of them popping up everywhere!

  • @IdoF47
    @IdoF47 6 лет назад

    Very good video and channel, thanks

  • @LucifaZ
    @LucifaZ 6 лет назад

    So glad I found your channel! I find these videos very helpful. I have a question about data structures (ds_maps/ds_lists): I've looked them up and it's very important to always destroy them when you don't need them anymore so that your game can free up memory. If I assign my data structures to a local variable, do I still need to destroy them when I'm done with them?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +1

      Thank you! Yes, I'm afraid that doesn't destroy it. What you're actually saving when you assign a data structure to a variable (local, instance, global, whatever) isn't the "data structure" itself, it's the ID. So the only thing that will happen when the local variable you assign the data structure to gets destroyed, is you'll lose your way of referencing it.

    • @LucifaZ
      @LucifaZ 6 лет назад +1

      Ah makes sense! Thank you :) Edit: So that's why in the debugger a data structure is first shown as an ID instead of the actual list

    • @igorthelight
      @igorthelight 6 лет назад +1

      important tip:
      Use "Cleanup" event instead of "Destroy" event, because "Destroy" event is called ONLY if you destroy an object by instance_destroy() function!
      So, "Destroy" event will NOT be called if you loading the next room, for example!

  • @aristoteles3843
    @aristoteles3843 6 лет назад

    Very useful video thank you

  • @AllSquirrelsGoToHeaven
    @AllSquirrelsGoToHeaven 5 лет назад +1

    Hey, I don't know if you have an answer for me on this or not but how do I avoid stagnation? It's depressing honestly, I've tried over and over to make a game, I don't lack in skill when it comes to creating any of the required media but I often start a project, get it to a certain point and then give up on it. It drives me nuts, I've even abandoned creating games altogether more than once but it always just leaves me feeling empty. Creation is in my blood, I have to make things or my life just falls to shit. Strangely enough, even knowing this, I still can't finish one damned thing. It's as if someone gave me all of the tools and information that I need and instead of using them to focus on one thing I just find myself frustratingly distracted and immobile. I've tried giving it time, I've tried forcing myself, I'm at a loss, I just seem to be stuck and I don't know how to get out.

  • @_bubblezzzzzz_
    @_bubblezzzzzz_ 2 года назад

    Thank you

  • @miladx2143
    @miladx2143 4 года назад

    I wish you were my math teacher 😊

  • @GabrielMatusevich
    @GabrielMatusevich 6 лет назад +1

    it's very funny but yesterday I was wondering exactly what type of optimization could be made in GMS2 (mainly in scripts). I think that for beginners the stranger thing to wrap our head around is the fact that there is a bunch of code running every single frame, I sort of understand now why in games like League Of Legends there are a lot of calculations done every 0.5 seconds instead of every frame.

  • @Mo447
    @Mo447 6 лет назад

    What editing software do you use?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад

      Adobe Premiere Pro, but to be honest I don't know if I can recommend using it because there's a lot that frustrates me about the program. It also probably doesn't help that I just hate the process of editing lol :)

  • @DamianKomorowski
    @DamianKomorowski 4 года назад

    Friend linked me this video. Great job but I have one issue. Instance deactivation isn't worth it really. For simple objects (i.e trees in RPG) it's better to just disable visibility outside view. Activation and deactivation just takes too much processing time, even when run every few seconds. Other than optimization issue it might create lots of bugs with addressing not activated instance.
    Deactivation is better than setting visible=false only for objects that run heavier code, but then most of the time you want them to run it still. There is not really many examples when activation could be used efficiently.

    • @thomasrosebrough9062
      @thomasrosebrough9062 3 года назад +1

      Personally I made a game with a room size of 26000 by 26000 and thousands of objects. Deactivating was hugely helpful in making it run effeciently.

    • @DamianKomorowski
      @DamianKomorowski 3 года назад

      @@thomasrosebrough9062 Well yes, because instance deactivation also limits draw calls by eliminating objects in the game. But the process of deactivation and activation takes more computing power than necessary.
      And if we want to flex at numbers I was running 100k spaceships in a dog fight "of screen" on Intel Atom 1.06Ghz in 59-60 FPS

  • @sebaVRarg
    @sebaVRarg 3 года назад

    when i develop for android, i see real fps 700 but in game it get framed i dont know why, my light renderer maybe

  • @BIGBIZDRIZ
    @BIGBIZDRIZ 6 лет назад

    great video

  • @fierorecensione5828
    @fierorecensione5828 Год назад

    top video!!!

  • @antoinec2161
    @antoinec2161 3 года назад

    (sorry for my english I am french) : I tried to make a game with a home-made 3D graphic motor (with projections and triangles) but when a place more than 1 tiny room, my game drop to 5fps :/
    I can't display more than 1000 of triangles without a drop of fps :(
    But your video help a little, thank you

  • @TheAluna26
    @TheAluna26 3 года назад

    i just started one week ago my first simple game and i finished the gameplay today i just need the design but im not good at pixelart or design :P

  • @sixiangyang
    @sixiangyang 6 лет назад +1

    nice tutorials

  • @jaxdrumm2195
    @jaxdrumm2195 6 лет назад

    Helpful!

  • @igorthelight
    @igorthelight 6 лет назад +1

    What if instead of creating var's in the Step or Draw events, just create them as instance variables in Create event. Then only chage them in Step or Draw events. Example:
    Look at 7:33
    What I mean is:
    // In Create event
    cam = view_camera[0];
    cleft = camera_get_view_x(cam);
    ctop = camera_get_view_y(cam);
    cw = camera_view_get_width(cam);
    ch = camera_view_get_height(cam);
    // In Step event
    // All other code

    • @igorthelight
      @igorthelight 6 лет назад +1

      If you write in Step event:
      var my_variable = x * 2 + y * 2;
      It will be created, assigned and deleted every Step. But if you do like this:
      // In Create event
      my_variable = 0;
      //In Step event
      my_variable = x * 2 + y * 2;
      It will be created just once in Create event. In Step event variable will be only changed and it will be deleted only once in Clean-Up event.
      Correct me if I'm wrong.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +1

      You could do this. Certainly as I note in the videos, the get_width and get_height function calls/variables should be moved to the create event and declared just once. But the "cleft" and "ctop" variables are the camera's position, and unlike the camera's width and height, its x and y position ARE going to be changing as the game progresses. So we need to update those every step (so, keep them in the step event).
      As for your second point - you're correct. Temporary variables are created at the start of the script, and destroyed once that script finishes running. The instance variable will stick around until the object is destroyed. In this case it doesn't really matter what way you go about it - the memory is managed fine either way. But if you needed the camera's co-ordinates elsewhere (say, in both the step event and draw event) then it will be more useful to have it as an instance variable.
      Hope that makes sense. Great questions!

    • @igorthelight
      @igorthelight 6 лет назад +1

      Thanks!

  • @survival_man7746
    @survival_man7746 3 года назад

    To myself:
    Go to 17:38 to see the summary

  • @Lackingworth
    @Lackingworth 6 месяцев назад

    this video is 6 years old rn this person could have gotten married and have children or dead , the possibilities are endless

  • @necrodrake3342
    @necrodrake3342 4 года назад

    There is also instance_place_list I think lul

  • @hitwalkhook3831
    @hitwalkhook3831 5 лет назад

    In short:
    You are doing something wrong if you are manually writing code for every object instead of making a group for them or if you are using a mechanic that would require collision check on anything what collides with the same thing.
    Also another tip.
    Make use of surfaces well guys.