Jump to content


RubixCube

Member Since 02 Dec 2008
Offline Last Active May 11 2012 03:50 AM

Topics I've Started

Collision Detection Efficiency

28 April 2012 - 08:42 AM

I've been breaking out of Game Maker with SDL/C++ recently, and learning what's going on at a lower level has brought up some questions. I'd like to get the basic idea of how Game Maker's collision detection works (with collision_line, specifically) in relation to what I'm doing.
An example being:
//check below the character for a wall
collision_line(char.x,char.y+sprite_height+1,char.x+sprite_width-1,char.y+sprite_height+1,wall,0,0);
So far, my method in SDL/C++ for something like collision_line above has been to loop through all the instances of the wall objects, check if the walls top is less than or equal to the character's bottom, and adjust accordingly.

My question is, if I were to carry my method in SDL/C++ (looping through instances to check wall.var vs char.var) to Game Maker, would it be faster, slower, or the same as collision_line? If collision_line uses the same idea, but does it efficiently, I'd be okay with just knowing that. If anyone has an idea of how it works on a lower level, it would be much appreciated.

Cutscenes with Timelines

30 January 2012 - 11:38 AM

I've been trying to figure out how to do cut scenes. It's one of the last pieces I need for a game's engine that I'm programming. When it comes right down to it, I need a way of imitating button pressing so that the cut scene feels like the player is watching the character control itself for a little bit. A solution that I've come up with is to painstakingly plot every action of the cut scene and on what frame it needs to happen, and do it on a timeline. Then, all I'd need to do is copy and paste button actions into specific frames on a timeline. I'm okay with doing this kind of leg work, that's not the problem.

Unfortunately, other problems rise out of this. With the character, I already have systems set up where some things naturally take care of themselves. For example, friction, if you'd imagine, makes things complicated because I can't simply set the character's speed to something once and leave it like that. Friction will slow down the character, making it so that I have to literally plot out every single frame so that there's no difference between me holding the button, and the timeline "holding" the button. A cut scene could be anywhere from a couple of seconds to a full blown minute. At 60 frames per second, I don't want to be plotting out 3600 frames. I know it's an exaggeration, because the character won't always be moving, but it's still really high up there.

So is there a way to just duplicate frames, or maybe there's something to tell game maker timelines "do this between frames 40 and 200?"
Or maybe there's a better way to do this entirely. Is there a way to imitate keyboard_check functions? I thought about making the movement system run on boolean variables instead of keyboard_check functions. The keyboard_check_pressed and keyboard_check_released functions could switch the variables on or off. Inside of step, there could be an independent check for each variable that does whatever a normal keyboard_check function would do. Then, in the timeline I could bypass the functions and just manipulate the variables directly, but it seems really inefficient and pretty silly. Anyone have any ideas?

Text Wrapping *solved*

06 December 2011 - 05:38 PM

I have a system right now that will parse strings of text and add in the new line character '#' after it hits a pre-defined margin. So I have a MARGIN variable set to something like 40, so it will display a maximum of 40 characters onto a line before it loops back to find a space between words to insert the newline. What I'm wondering is if instead of checking something like if lineLength >= MARGIN, is there an easy way to check if the string is going off of the screen. I need it to be more flexible because in this case because I don't know where in the room the string is going to start being displayed.

draw_text causing serious lag

05 December 2011 - 05:45 PM

So, I've been making an object that allows scrolling text/word wrap for dialouge boxes without pausing the game. That way scrolling text can be drawn while you're playing. Unfortunately,  it lags like crazy the first time it runs. After it runs once, it seems to run perfectly smooth afterwards.
I've been sitting here slapping myself because I had thought that my algorithm was just a slow piece of garbage that was causing lag, but I'm on a pretty fast computer so I decided to test more. I deleted everything but the variable that holds the string and the boolean like variable that I used to tell the object to draw_text. So no scrolling and no wrapping and no box. Guess what, it still lags. I've tested it on more than one computer and its lags on all of them.

Here's the file-
https://docs.google.com/open?id=0B70P0cpMyQfdMmQxNTZlMDEtYzhkNS00YjY5LWIxYTMtZGU1MjdkZTlkMGE3

For people who don't care to download it or people who aren't using 8.1 (sorry) here's what it basically is.

Two objects. One object is just moving so I can see the lag, and the important one has this:
CREATE:
active = 0;
fullText = "What is a man, a miserable little pile of secrets?";

DRAW:
if (active)
{
    draw_text(x,y,fullText);
}

PRESS SPACEBAR:
active = !active;

What on Earth is causing this serious lag? Why is it only lagging the first time I "activate" the object? If the function is just slow, what should I use instead?

coming from c++

05 October 2011 - 05:12 PM

I've been programming in gml longer than c++, but I still have some lingering questions.

First off, how does game maker treat variables that hold 0 or 1? I've just assumed it treats them as interchangeable with true and false. Meaning every variable is a potential boolean when it holds 0 or 1, right? It does this, supposedly, by treating every variable above 0 as true, and every variable 0 or below as false. But will this still function the exact same as 0 and 1?
While we're at it, can you assign conditional statements into an intended boolean variable?
Like so: boolVar = !a && !b;

Is the order of operations for boolean comparisons the same as it is in c++? (==/!= then && then ||) I don't even know where ^^ falls on the list, so bonus points to anyone who knows that.

Is there an easy way to reference single characters in a variable holding a sentence? Recently, I've been working on a re-usable scrolling text script, but I need to access single characters at a time. In c++ you could just put brackets that held the place number in front of the variable like stringVar[5] (I'm not talking about cstrings).

Does Game Maker store memory for arrays and strings dynamically? Just wondering, this question doesn't really need an answer since I don't have a practical application for it.

Lots of questions. Thanks in advanced to someone who can answer them. I'd return the favor if I could, but odds are if you're answering the questions you're a better programmer than I am, so you probably don't need my help.