Activating instances only on the current platform

B

Brandon Paris

Guest
Hello everyone!

Hit a bit of a wall with the game Im making. Right now I have it so only the section of ground the player is currently standing on is visible (this is an isometric game), all others are invisible. Im using a collision event to do this with a:

Visible = other.visible Code in the collision event

I need all the instances on top of the platforms to deactivate if the player is not standing on those platforms. Make sense? To do that Im using collision events for all the instances on all the platforms - this has LAGGED THE CRAP out of the game, as you can imagine.

Is there any efficient way to do this so I can deactivate instances not on the current platform, ideally without using fps-eating collision events? Thank you!!!
 

Becon

Member
First thing, posting more code would probably get you faster responses.
Second, is your collision event in the objects that could be stood on or the player? If they are in each floor object...then every object is searching for a player....where as if the event is in the player...the player is only looking at what they are standing on. This would probably speed it up a bit. I have something like that in one of my games too. Each floor object type gets some code that tells it's floor type, grass, swamp, mountains, etc. Then...when the player makes contact it checks for what type of floor it's on.
If contact with grass, floorType = grass.
Then, if floorType = grass,
{
Do things!!! Like run a script that looks and sees, Player is on grass...only make the grass objects visible and hide the rest.
}
 
B

Brandon Paris

Guest
@Becon Thanks very much! I think I'm on the right track. I switched the collision event from the platform checking for the player to the player checking for the platform. However, I'm still a bit confused as to how to affect the other objects.

At the moment there is only 1 floor type - a snow platform that is repeated multiple times to form the level. Each platform instance has its own different instances (arrangements of trees, houses, etc.) on top of it. What I'm trying to do is make it so that only the instances on the current platform are visible, without using collision events. If I had grass platforms and swamp platforms that had the same static arrangement of terrain every time, I can imagine it would be easier - but since I'm using copies of the same instance to build the level, I'm trying to figure out an intuitive way so that each platform instance knows which tree objects (for instance) are on it so it doesn't make ALL the trees in the whole level invisible when I toggle them off in a script.

I'm sorry if that's not making any sense. I've attached a picture to show what once section of platform looks like. When the player walks off the platform, the next section appears with all of its respective objs.
 
B

Brandon Paris

Guest
Anybody? I'm pulling my hair out here. I've tried everything. Is there no way to set the visibility of an object according to another without using FPS-destroying collision events? I'd really really realllllllyyy appreciate the help
 

samspade

Member
Anybody? I'm pulling my hair out here. I've tried everything. Is there no way to set the visibility of an object according to another without using FPS-destroying collision events? I'd really really realllllllyyy appreciate the help
I'm not fully sure I understand the question, but I think what you're saying is this. You have a game where the player can stand on one of multiple platforms. These platforms also have other objects on them. You only want the platform (and associated objects) the player is standing on to be visible. You actually have succeeded at this but it makes your game slow.

Probably the best way is to have each platform track all associated objects, most likely by storing those instances ids in a list or array. Then have the player, and only the player, do a collision check for the platform. Whenever the states switch, e.g. whenever you go from being on a platform to not being on a platform and vice versa have that specific platform iterate through it's list of ids and change the visibility. Depending on what you need, you might even be able to activate or deactive. So, psudo code would would like this:

Code:
///platform create event

associated_instances = ds_list_create();
with (some parent that applies to all associated instances) {
    if (place_meeting(x, y, other)) {
        ds_list_add(other.associated_instances, id);
    }
}

//if the platforms create the associated instances, you could just add the ids to the ds list at that time.

///player step event

prev_platform = platform;
platform = instance_place(x, y, platform);
if (platform != prev_platform) {
    if (prev_platform != noone) {
        scr_deactivate_platform_instances(prev_platform);
    }
    if (platform != noone) {
        scr_activate_platofrm_instances(platform);
    }
}

///scr_deactivate_platform_instances

var _id = argument[0];
with (_id) {
    visible = false;
    for (var i = 0; i < ds_list_size(associated_instances); i += 1) {
        associated_instances[| i].visible = false;
    }
}

///scr_activate_platform_instances

var _id = argument[0];
with (_id) {
    visible = true;
    for (var i = 0; i < ds_list_size(associated_instances); i += 1) {
        associated_instances[| i].visible = true;
    }
}
This code likely won't work as is, given that I don't really know how other things work for you, but hopefully it serves as an idea. Finally, you should consider deactivate all instances outside of a certain range (generally the view size) so that the platform checks are easier to do.
 
B

Brandon Paris

Guest
@samspade Thank you for your reply and ideas! You articulated the problem perfectly. Im relatively new to programming, so some of the functions such as loops and lists Im less comfortable with, but I'm going to try and implement the ideas you had and see how it goes :)

I think the main thing will be figuring out how to determine whether a platform is the current platform or a previous platform. Once I can figure out how to make that distinction, everything else will be downhill. If you'd like I can give you a credit once the game is finished. Thanks again
 
B

Brandon Paris

Guest
@samspade Yeahhh I can't figure it out :/ I don't think I'm skilled enough at coding to realize what I'm doing wrong. I tried a bunch of other variations. I might just end up paying somebody to get this code working or scrap the project. Thanks for your help though
 

samspade

Member
@samspade Yeahhh I can't figure it out :/ I don't think I'm skilled enough at coding to realize what I'm doing wrong. I tried a bunch of other variations. I might just end up paying somebody to get this code working or scrap the project. Thanks for your help though
Well, don't give up coding :) even if you give up the project. I started less than a year ago and you pick up stuff quick if you keep at it. If you don't enjoy beating your head against a problem until you solve it, I would say find something else. At least for now I think it's more important to stay interested and keep coding than it is to persevere on any specific thing. I gave up my first project because even though I thought it as doable, it turns out it wasn't really. There was a while towards the end where I would just not code because I wasn't making progress and wasn't enjoying it.

If you're the type of person who likes beating your head against something until you solve it though, I wouldn't give up on this yet. It's not a super difficult problem though it isn't a beginner level problem either. If you wanted to keep at it, I would say start another smaller project where the only goal was to get this one idea working and use just two platforms. Start without any objects on the platforms and after you get that working start adding objects. With only two you can hard code all the instances into the list. If you really wanted to hire someone, I'd look at your project and give you an idea of how long I think it would take. Just send me a PM.

But again, there's lots of great tutorials out there for projects and ideas and such and keeping it small enough to do yourself is generally what you want. I'd only recommend hiring someone if either it is (a) really really cheap or (b) you have a good idea of everything in the project you need to hire someone for in order to finish. You don't want to get trapped in some loop of hiring someone to do something only to find out that the next thing is also something you need to hire out. If the game is virtually done but you know you need help with art, or sound, or some aspect of networking or integrating a leaderboard on steam etc. then it might be worth it otherwise, it generally isn't.
 

TheouAegis

Member
Like, are all the objects ON the platform or is it including objects above the platform but not actually on the platform (like enemies flying by)? Or objects connected to the other objects that are attached to the platform?

I mean, if you put every object's sprite's origin at the bottom of the sprite, and the platform's origin at the top, then you could just check if an object has the same y as the platform before deciding to deactivate it.

However, since you'd want to activate things as well and maybe even include objects that aren't directly attached to the platform, an array of ids would be better because you can always modify deactivated objects by their id and you can easily restrict (de)activation.
 
Top