Merus

Gamemaker Questions Thread

Recommended Posts

We don't have this thread.

 

So I'm making a game where hounds are chasing the player through a forest. The player is leaving a blood trail behind them. I'm storing where the player's moving in a grid and the hounds follow that trail if they can't see the player, and it works well and it's tense and exciting. But I want to leave a visible trail.

 

I don't want to spawn fifty thousand instances for this because I'm really just permanently applying a sprite to the ground. I'm not really sure the best way to go about it - apparently I can't draw on backgrounds, and surfaces aren't persistent for long enough to store something like this. I could track the location of each blood sprite and then draw onto the surface if it's in my view, which I can do, but I'd prefer not to track this if I don't have to.

 

I'm basically writing everything in GML.

Share this post


Link to post
Share on other sites

In my experience, there is no fantastic way to accomplish this kind of thing in Game Maker. The engine just isn't very good at drawing hundreds of sprites to the screen fast enough to allow a decent framerate. No way of getting around this, so you're just going to have to optimise as best you can. Which means you have to try and lower the amount of sprite draws per frame.

 

First of all, yes you are going to have to track the location of each blood sprite. You can't just have a buttload of sprites drawing off-screen, it's not efficient. In fact, as far as I can tell, it costs just as much performance to be drawing sprites off-screen as it does on-screen, and you'd be drawing them for literally no reason at all. If a sprite is off-screen, don't draw it. If you want better performance you should do this with every object in the game that might be leaving the screen view.

 

Something else that might help is to limit the actual number of blood sprites that are being created. What I would do is increase the size of the blood sprite (not too big) and have it spawn only when the player steps a certain distance, as opposed to every frame in which the player is moving.

 

Hope this helps.

Share this post


Link to post
Share on other sites

Hello!

 

I'm currently making a platformer and I'm having some issues with setting up the player collision to "danger objects".

The way it's supposed to work is that when the player collides with a dangerous object the PC gets thrown back in the direction it came from.

 

I had a solution where I would check for each individual object, but considering that I then would need to write code for each different kind of dangerous object and hoped instead to find a way to write one solution that would look for a variable in these objects instead.

 

I tried this:

 

 

if ((place_meeting(x+hsp,y,other))&&(other.state == 'danger'))
{
    while(!place_meeting(x+sign(hsp),y,other))
    {
        x += sign(hsp);
    }
    
    state = 'hurt';
    hsp = 2.5*(-cDir);
    vsp = -jump_speed;
}
 
//Vertical Collision with danger object
if ((place_meeting(x,y+vsp,other))&&(other.state == 'danger'))
{
    while(!place_meeting(x,y+sign(vsp),other))
    {
        y += sign(vsp);
    }
    
    state = 'hurt';
    hsp = 2.5*(-cDir);
    vsp = -jump_speed;
}
 
Basically, I have a variable in the dangerous objects called "state" which I assign the be "danger". For some objects the state is always "danger" whilst for others it switches between a few different states.
However, now the player character does not react to these objects at all. 
 
Am I wrong in assuming that I could use a variable within an object like this or am I just messing up my "detection" logic here?

Share this post


Link to post
Share on other sites

As far as I know "other" doesn't work in the way you're thinking it does. "other" can only be used in a "with" construction, which is when you're controlling code in another instance and want to call variables from the object you're in. Below you can see this code executed in an object that isn't oEnemy, but controls the variables inside oEnemy. Using "other" indicates the instance that isn't what the "with" construction is calling.

 

with(oEnemy){
    x=other.x
    y=other.y
}

So in the context you have other doesn't work.

 

Gamemaker has functions that detect collision then return the instance id of the collided object. So what you could do is instead of using place_meeting to detect the collision, you can use collision_point() at the (x,y) of the player. That function returns the ID of the collided object, so now all you need to do is put the output in a variable and use that to call variables from that instance. So something like this would work:

var collID=0
collId=collision_point(x,y,all,1,1) //this stores the output of collision_point in collID
if collID.state == "danger"{
     //do whatever
}

Share this post


Link to post
Share on other sites

Thanks, I'll try it out!

 

The reason I'm using place_meeting rather than the other collision functions is because it actually stops the player object from entering other objects when used in the way I'm using it here, rather than moving it back out of the collided object after the collision has occurred.

Share this post


Link to post
Share on other sites

Mupp, regardless of your other issues, I would also consider using the parenting function of gamemaker objects to make things easier on yourself. It's the closest you can get to object oriented in GM, and it will help keep from repeating your code and dealing with maintenance issues down the line.

Share this post


Link to post
Share on other sites

Mupp, regardless of your other issues, I would also consider using the parenting function of gamemaker objects to make things easier on yourself. It's the closest you can get to object oriented in GM, and it will help keep from repeating your code and dealing with maintenance issues down the line.

 

Oy I second this! Especially when you're working out exceptions to stuff, having a bunch of objects under one parent is really useful.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now