Optimizing the game...
#1
Posted 08 May 2012 - 01:12 PM
#2
Posted 08 May 2012 - 01:22 PM
Do the key check commands slow the game any more than using the key check events? Would it be a bad idea to just put everything in the step event (using "else if" statements, of course)? Or should I really use the events as much as possible?
From what i have learned here on the forum, you should use the events as much as possible. And, theoretically, putting EVERYTHING in a single step event will slow down your game. This is because the game will not take a step until all of the code inside each step has been performed, but with events it just checks for an exception. Correct me if i'm wrong, someone!
#3
Posted 08 May 2012 - 03:03 PM
Events are user-friendly ways of using code.
E.g. "Mouse Left Press Event" is the same as checking "if(mouse_check_button_pressed(mb_left)) { content of event }".
A computer always detects if you're pressing or moving something, it's just a matter of whether you want to detect it as well.
I suggest using programming as much as possible. I never use anything but Create, Draw, Alarms and Step events.
However, the killer of Game Maker is essentially the Draw event. Have as few Draw events as you possibly can - these are the most time consuming events in Game Maker, as they handle drawing.
A few handy tips;
1. Do not put any unnecessary code anywhere.
2. Never execute code that doesn't have to be executed at the given time.
3. Perform calculations as little as possible (if you're using a calculation many times, store it in a temporary variable in the start of the event - if it can change, else in a local variable in create event).
4. Clean your code.
5. Clean it again.
6. Double-check it.
7. Scavenge for more unnecessary double-calculations until you're absolutely sure there are none.
Edited by Jobo, 08 May 2012 - 03:05 PM.
#4
Posted 08 May 2012 - 03:40 PM
You're wrong.
Events are user-friendly ways of using code.
E.g. "Mouse Left Press Event" is the same as checking "if(mouse_check_button_pressed(mb_left)) { content of event }".
A computer always detects if you're pressing or moving something, it's just a matter of whether you want to detect it as well.
I suggest using programming as much as possible. I never use anything but Create, Draw, Alarms and Step events.
However, the killer of Game Maker is essentially the Draw event. Have as few Draw events as you possibly can - these are the most time consuming events in Game Maker, as they handle drawing.
A few handy tips;
1. Do not put any unnecessary code anywhere.
2. Never execute code that doesn't have to be executed at the given time.
3. Perform calculations as little as possible (if you're using a calculation many times, store it in a temporary variable in the start of the event - if it can change, else in a local variable in create event).
4. Clean your code.
5. Clean it again.
6. Double-check it.
7. Scavenge for more unnecessary double-calculations until you're absolutely sure there are none.
I see... then i was mis-guided here on the forum before.
Would you say that it is outright WRONG to use key-down events etc? If it's exactly the same as putting code in the step event, then i don't see the harm in using them, as i feel that it keeps my code more organized and "divided" rather then just being a 10000 lines long text with only comments to separate chunks of code apart. I assume, however, that the reason you suggest programming as much as possible is that you don't get lazy and always improve your programming skills that way?
#5
Posted 08 May 2012 - 03:49 PM
#6
Posted 08 May 2012 - 04:35 PM
Yes I personally suggest manually creating these events in Step event (or, for better precision when moving something, End Step event).I assume, however, that the reason you suggest programming as much as possible is that you don't get lazy and always improve your programming skills that way?
It's good programming practice if you're somewhat novice, you learn more of how Game Maker works (code-wise), and it ups your experience with programming in general - even when moving onto actual programming languages ("Hm.. Game Maker had a keyboard_ function, maybe this language has something similar.."). It really gives a nice way of thinking in general terms, when approaching something new.
I prefer programming these events myself for speed of use, instead of wobbling through multiple events to find what I'm looking for.
Click on object, click on Step, open code, and there's pretty much all the base coding.
Of course, with GM8.1 allowing you to rename "Execute code" action blocks, this allows you to organise it even better.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











