You might have met such situations where you need to find nearest coordinate at object's edge towards a point, or find actual (non-bounding box) distance between objects, or other things of this kind. If so, you may find this example useful.
Used method is relatively simple - first find approximate distance with distance_to_point function, and then 'fix precision' by using a 'while not position_meeting' loop.
This way maximum amount of calculations will be limited to cP * iR + dP, where
cP is time needed to check object for collision against a single point
iR is instance 'radius' (maximum distance from origin to corner of bounding box)
dP is time needed to find distance between object's bounding box and point
So it should be acceptable for many cases of usage. If you need to reduce amount of calculations further, could alter distance decrementation 'rate' in two while loops. Removing while() loops entirely would give rather approximate distance calculation.
Tululoo: scores and user input
Today I've made a example of implementing local highscores (via webdata functions) and user input (via keyboard_check_*... at least until I'll add some code to event handles in framework) in Tululoo.
Love2d: Simple compilation to executable
copy /b love.exe+%1 "%~dpn1.exe"How to use this:
- Create a file called 'compile.bat' in the same directory with Love2d runner.
- Paste above code into it.
- To compile a game, drag it's .love\.zip onto your compile.bat - an executable (compiled game) will appear next to it, named after game's file.
GameMaker: resource packs refactored
Image: Those awesome futuristic tiles by Morphosis, now in a single aligned image.
I've always found standard resource packs that can be downloaded from site of YoYoGames, however rarely ever used something from them because it took multiple minutes to simply look through everything in there in attempt to find something matching.
So, decision was made to improve the situation a little bit, at least for myself.
Changes include graphics being sorted into categorized folders nicely, transparent background color in graphics, relevant tilesets being merged into larger images, and more. Overall, if you've ever considered using original pack, you might find this useful as well.
See ReadMe for more information.
GameMaker: Executable “self-destruction”
In some rare cases, you may need executable to 'vanish' (delete itself) upon shutdown.
The most trivial case for such behavior would be updating (when never version of game is downloaded, and there is no reason to keep old one).
Less common cases include removing game under specific conditions (note: this is not an appropriate way of stopping user from playing it) and single-use utilities (which user will never need to run again for sure)
However, as you may noticed, executable's cannot delete themselves while running.
So, some tricks are needed.
The easiest one is to have second executable to run afterwards and delete the first one.
To illustrate source of such 'clean-up' program, I have used language that provides smallest output file size, while still keeping it readable. In this case, it's C++.
#include "windows.h" #include <tchar.h> int APIENTRY _tWinMain(HINSTANCE ii, HINSTANCE pi, LPTSTR lpCmdLine, int ncs) { for (;;) { if (DeleteFile(lpCmdLine)) return 0; Sleep(100); } }
(you can download compiled version of this code here)
Structure of code is quite simple, as you could notice - we include two required headers (windows.h for used functions and tchar.h to allow main function definition to be written this way); main function itself consists of a perfectly infinite loop (heard of these?) in which program attempts to delete file given by command line and quits on success, or waits 0.1 second and tries again.
Integration on GameMaker side is simple as well - all you have to do is to run program described above just before game ends with game's executable location as a single argument. Fortunately function parameter_string(0) can be called to retrieve mentioned location, so code can be minimized to
execute_program('DeleteThat.exe', parameter_string(0), false)
Obviously, this way you will have a secondary executable remaining upon success of all operations, which user will have to delete manually (or not delete at all, in case of use in updater).
To save user from potential wondering about purpose of small executable that appeared after game's end, it can be unpacked into game's temporary folder.
Example illustrates typical setup for such game: secondary executable is included inside of game, and is unpacked & launched at game end. To test it, compile game into executable file, run it (in this case it's just a placeholder window) and close it by pressing Escape or window button - executable will vanish in moments after process termination.
ActionScript3 – show DisplayObject hierarchy
Inserting video into Tululoo game (HTML5 Canvas)
Video credit: 'asdfmovie song by LilBruceWayne'
As you may know, HTML5 standard includes <video> tag support.
This adds some crazy interesting possibilities that can be used in games as well.
A common wish is to have a video playing as part of game or as its background overall.
Here I'm going to explain methods of doing this in Tululoo.
(implementations in languages and frameworks that allow 'low-level' access to javascript would be pretty similar too)
C# joystick tracking via winmm.dll
Contains required structs, functions, and fallback to joyGetPos if joyGetPosEx does not work for some reason. Continue reading