I have begun to look into adding sand to the generator, however I have hit a bit of a snag. Currently the sand physics simply checks if there is an object below it that can support it (with the parent "par_solid") OR if there is another block of sand below it (with the parent "par_nosolid") if neither of these objects are present, the sand block will continue to fall by 16 pixels every 5 steps until it comes in contact with a "par_solid".
The problem is this -- Since it needs to deactivate objects, if a "par_solid" that is supporting a sand block gets deactivated the sand it was supporting just simply falls down and deactivates, only to be reactivated usually INSIDE or BELOW the "par_solid" that was previously supporting it... So what I need to figure out is a way to keep the sand from falling when it's supporting "par_solid" is deactivated/out of view.
I've had a few idea's so far as for how to prevent them from falling, but am not quite sure if they would work or really how to implement them... Before I get to that though I will post the deactivation code.
//BEGIN STEP EVENT
if activate = true
{
instance_activate_all();
instance_deactivate_region(view_xview[0] - (view_wview / 4),view_yview[0] - (view_hview[0] / 4),view_wview[0] + (view_wview[0] / 4),view_hview[0] + (view_hview[0] / 4),false,true);
}
Basically what that code does is "activate" get's set to true once the map has fully generated, so that only once the map is generated will it begin to deactivate outside of the view.So my only idea that really has much plausibility was to simply check if "par_solid" was supporting a sand block after "instance_activate_all()" and before "instance_deactivate_region()" and then re-activate those blocks after the "instance_deactivate_region()" takes place, but the problem with that is that it would probably require the ID's of ALL the "par_solid" supporting a sand block to be checked and the ones supporting a block to be returned and saved somehow.
The problem with this is well, how to save them? There could be any number of "par_solid" blocks supporting a sand block, there is little way to anticipate how many there would be, yet alone get the ID values of all the ones that are.
What I had come up with was something along the lines of taking a blank string "" and then for every "par_solid" that came back as supporting a sand block, to add it's variable to the end of the string followed by a space -- So for example "" would become "283293 ", then "283293 878243 " and so on. Then once all of the "par_solid" blocks had returned the value it would have an alarm set to run a code that would check for the ID numbers and reactivate them 1 by 1, using the spaces as a symbol showing where one ID ends and another begins.
As it reactivated the objects via their ID numbers, it would remove them from the string. The biggest problem with this idea is it would be ran every single "begin step" event, causing lots and lots of lag...
You know -- I swear I am massively over thinking this...
Any idea's of how to either do this differently or how to make my idea work right would be greatly appreciated.
EDIT: I should probably add that at the moment I have added the ability to add/remove blocks for the sake of the engine at some point being used in a game, this is why the sand has physics, so it can react accordingly to destroyed blocks.
UPDATE: I am embarrassed by how much I was over thinking this... All of my initial thoughts were based off of "How to keep the block below sand from deactivating, when the real solution was "How do I deactivate sand physics when outside the view" -- And with no doubt the second question was easier to solve. For others that may also encounter this problem, I will tell everybody my solution...
The solution was simple, I simply made all instances half the view height below the view deactivate, and then made all physics not apply to blocks that were below the view. The half of view leeway is enough to prevent any glitches/bugs from occurring. It doesn't even have to be half the view, simply make physics not apply outside of the view and then a bit further down deactivate blocks, this ensures that any blocks below the sand don't deactivate before the sand's physics are turned off.
Edited by cori5555, 18 July 2011 - 02:49 AM.











