milifusion.blogg.se

Game maker screen wrap
Game maker screen wrap








game maker screen wrap

game maker screen wrap

When you create an array, memory is allocated to it based on its size.

#GAME MAKER SCREEN WRAP CODE#

When using the YoYo Compiler (YYC) targets, if you reference global or instance variables multiple times in a script or code block, assign them to a local variable at the start of your code and reference that local variable for greater performance.Īrrays are easy to use and require less memory than data structures, but they can still be further optimised. If the same function call or calculation appears in a code block two or more times, think about creating a local variable for it. Local variables are fast to process in-game, so make the most of them. Make your code cleaner with local variables The same idea should be applied to functions too, where you should assign sensible names to arguments, and use clear formatting and local variables where required to make it as readable as possible. The memory and resources required to create those local variables are negligible, and greatly improve the clarity of your code. Var local_y = y + lengthdir_y(100, p_dir) ĭraw_sprite(sprite_index, image_index, local_x, local_y) Var local_x = x + lengthdir_x(100, p_dir) It would be far better expressed as: var p_dir = point_direction(x, y, mouse_x, mouse_y) While not completely unreadable, it is inefficient (the point_direction() function is called twice, for example) and it is messy and awkward to look at. For example: draw_sprite(sprite_index, image_index, x + lengthdir_x(100, point_direction(x, y, mouse_x, mouse_y)), y + lengthdir_y(100, point_direction(x, y, mouse_x, mouse_y))) This means that you can add as much whitespace around your code as required without needing to worry about keeping your comments short or only using them sparingly.Ĭontinuing on from the above point about programming style, one thing that a lot of beginners do is to cram as much into one line of code as possible.










Game maker screen wrap