Game Maker Studio writing in exactly in the middle of a GUI - game-maker

I'd like to make a pause screen.
In the game the view follows the character and when paused I want the text to be exactly in the middle of the screen. I am using a draw GUI event to display text where the user can see it.
I was thinking of halving the length and width of the port but could not find a function which gave those numbers.
If there is one, what it is, and if not how can I achieve this?

I think I have solved this.
In the GUI event, I use view_hport[0] and view_wport[0] in order to obtain the total length of the port then halve this number.

Related

How can I make a program wait in OCaml?

I'm trying to make a tetris game in ocaml and i need to have a piece move through the graphics screen at a certain speed.
I think that the best way to do it is to make a recursive function that draws the piece at the top of the screen, waits half a second or so, clears that piece from the screen and redraws it 50 pixels lower. I just don't know how to make the programm wait. I think that you can do it using the Unix module but idk how..
Let's assume you want to take a fairly simple approach, i.e., an approach that works without multi-threading.
Presumably when your game is running it spends virtually all its time waiting for input from the user, i.e., waiting for the user to press a key. Most likely, in fact, you're using a blocking read to do this. Since the user can take any amount of time before typing anything (up to minutes or years), this is incompatible with keeping the graphical part of the game up to date.
A very simple solution then is to have a timeout on the read operation. Instead of waiting indefinitely for the user to press a key, you can wait at most (say) 10 milliseconds.
To do this, you can use the Unix.select function. The simplest way to do this is to switch over to using a Unix file descriptor for your input rather than an OCaml channel. If you can't figure out how to make this work, you might come back to StackOverflow with a more specific question.

Qt5 progress bar

I am developing a Qt desktop application now. I need to show user indeterminate progress bar while my program is computing. I can't determine time of computing and can't determine number of steps, that's why in my realization using of an indeterminate progress bar is the only option.
I tried to use QProgressDialog. The only variant that worked (I mean showed user progress bar) was something like that:
QProgressDialog dialog("Computing", "Cancel", 0, 0);
dialog.setWindowModality(Qt::WindowModal);
dialog.exec();
//further code
But as you can understand, that further code didn't work while dialog was executing.
I also tried to use method show(), but Qt didn't render the dialog window, I mean during calculation window was transparent.
So, could you suggest some solutions that will help me to show user progress bar and compute at the same time? Computing time may vary very much.
To show the progress of some work in parallel to responsive UI we usually have to have:
UI thread not blocked by that parallel job
The worker thread (QThread) performing the job
UI should have Cancel button to stop the job
UI progress bar shows fixed steps [0...X] or looping
If the goal is to show 'floating' progress: How to show an 'infinite floating' progressbar in Qt without knowing the percentage?
If the goal is to create the progress bar showing some 'realistic' degree of work done:
You have to estimate the full time somehow then. Do the experiment calculation and measure the full time. Assume that will be average time. Then make the progress driven by timer so it is going for 1/2 of progress length and if not done then it assumes the remaining time is twice longer. And then check at remaining 1/4 again and again expect twice longer. Do that until very small fraction of progress remains, say, around 1% but visible for the user and make it stay there until full calculation done. As you can guess when the job is done you advance the progress to the end showing the user that results ready.
To completely answer this question you will likely have to break it to several less "heavy" questions. Try the progress driven by timer first. Then try to create your math calculation job on a separate thread and make it signal to UI. When you have more specifics on certain implementation parts then C++/Qt programmers will likely be able to answer.
Here are some examples: tutorial #1, tutorial #2 on timer-driven Qt progress.

How do I generate a waypoint map in a 2D platformer without expensive jump simulations?

I'm working on a game (using Game Maker: Studio Professional v1.99.355) that needs to have both user-modifiable level geometry and AI pathfinding based on platformer physics. Because of this, I need a way to dynamically figure out which platforms can be reached from which other platforms in order to build a node graph I can feed to A*.
My current approach is, more or less, this:
For each platform consider each other platform in the level.
For each of those platforms, if it is obviously unreachable (due to being higher than the maximum jump height, for example) do not form a link and move on to next platform.
If a link seems possible, place an ai_character instance on the starting platform and (within the current step event) simulate a jump attempt.
3.a Repeat this jump attempt for each possible starting position on the starting platform.
If this attempt is successful, record the data necessary to replicate it in real time and move on to the next platform.
If not, do not form a link.
Repeat for all platforms.
This approach works, more or less, and produces a link structure that when visualised looks like this:
linked platforms (Hyperlink because no rep.)
In this example the mostly-concealed pink ghost in the lower right corner is trying to reach the black and white box. The light blue rectangles are just there to highlight where recognised platforms are, the actual platforms are the rows of grey boxes. Link lines are green at the origin and red at the destination.
The huge, glaring problem with this approach is that for a level of only 17 platforms (as shown above) it takes over a second to generate the node graph. The reason for this is obvious, the yellow text in the screen centre shows us how long it took to build the graph: over 24,000(!) simulated frames, each with attendant collision checks against every block - I literally just run the character's step event in a while loop so everything it would normally do to handle platformer movement in a frame it now does 24,000 times.
This is, clearly, unacceptable. If it scales this badly at a mere 17 platforms then it'll be a joke at the hundreds I need to support. Heck, at this geometric time cost it might take years.
In an effort to speed things up, I've focused on the other important debugging number, the tests counter: 239. If I simply tried every possible combination of starting and destination platforms, I would need to run 17 * 16 = 272 tests. By figuring out various ways to predict whether a jump is impossible I have managed to lower the number of expensive tests run by a whopping 33 (12%!). However the more exceptions and special cases I add to the code the more convinced I am that the actual problem is in the jump simulation code, which brings me at long last to my question:
How would you determine, with complete reliability, whether it is possible for a character to jump from one platform to another, preferably without needing to simulate the whole jump?
My specific platform physics:
Jumps are fixed height, unless you hit a ceiling.
Horizontal movement has no acceleration or inertia.
Horizontal air control is allowed.
Further info:
I found this video, which describes a similar problem but which doesn't provide a good solution. This is literally the only resource I've found.
You could limit the amount of comparisons by only comparing nearby platforms. I would probably only check the horizontal distance between platforms, and if it is wider than the longest jump possible, then don't bother checking for a link between those two. But you might have done this since you checked for the max height of a jump.
I glanced at the video and it gave me an idea. Instead of looking at all platforms to find which jumps are impossible, what if you did the opposite? Try placing an AI character on all platforms and see which other platforms they can reach. That's certainly easier to implement if your enemies can't change direction in midair though. Oh well, brainstorming is the key to finding something.
Several ideas you could try out:
Limit the amount of comparisons you need to make by using a spatial data structure, like a quad tree. This would allow you to severely limit how many platforms you're even trying to check. This is mostly the same as what you're currently doing, but a bit more generic.
Try to pre-compute some jump trajectories ahead of time. This will not catch all use cases that you have - as you allow for full horizontal control - but might allow you to catch some common cases more quickly
Consider some kind of walkability grid instead of a link generation scheme. When geometry is modified, compute which parts of the level are walkable and which are not, with some resolution (something similar to the dimensions of your agent might be good starting point). You could also filter them with a height, so that grid tiles that are higher than your jump height, and you can't drop from a higher place on to them, are marked as unwalkable. Then, when you compute your pathfinding, as part of your pathfinding step you can compute when you start a jump, if a path is actually executable ('start a jump, I can go vertically no more than 5 tiles, and after the peak of the jump, i always fall down vertically with some speed).

How to achieve Typewriter effect in JavaFX?

I'd like to print a longer text letter by letter - as if someone is just typing it on a typewriter. What's the best approach here in JavaFX?
You'll just need to take a string and then lay it out letter-by-letter on to the scene to simulate a typewriter typing.
Iterate over the string and maybe increment an x,y position of the current letter to get it in place on the screen.
Take a look at the TimeLine object in the JavaFX 1.3 api, at each "tick" of the timeline you can write a new letter out.
A small random delay will make the layout appear more like typing (look at PauseTransition - which executes an action after a given delay - this could be bound to a var set randomly at each tick).
Hope this helps. Feel free to post it back here or to somewhere like jfxstudio.org when you get it working.

What is the maximum number of lines a TextArea control can hold?

I have an app that has text appended to a TextArea (TA). It automatically scrolls to keep the recent line added in view. Over time, this could be a lot. Do I have to worry about this? Is there an upper limit? And, if so, how can I prune the oldest lines of text?
There's nothing in the documentation, but if it gets too big you could run into memory issues. But we're talking collosal here.
It's easy enough to remove oldest lines using the slice() method

Resources