Jump to content
  • Advertisement
Sign in to follow this  
Dustin Booher

Having issues switching two assets positions

This topic is 2501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So im creating a "Falling Sand Game" but have run into an issue. What ive done is I have a grid containing one element per pixel and its 800x480 so its
_GRID[800,480]
The grid contains data of type _node, which is setup as follows:


public class _node
{
public _type _TYPE=_type._NULL;
public int _ID=-1;
}

In addition i have a
List<Sprite> Sprites
For holding all the sprite data. Right now I only have sand & Water working, but i want the sand to sink if water is direcly above it. I figured the best way to go about this, is to check if a Sand Element has A Water Element directly below it then switch the positions. Im Checking like this:



if (_Grid[_x, _y + 1]._TYPE != _type._NULL && (_Grid[_x, _y + 1]._TYPE != _type._SAND))
{
if (_Grid[_x, _y + 1]._TYPE == _type._WATER)
{
_sprite _TEMPS = _sprites[_Grid[_x, _y + 1]._ID];
_sprite._switch(Con,ref _Grid, ref _TEMPS);
_sprites[_Grid[_x, _y + 1]._ID] = _TEMPS;
}
}


So first it makes sure there is Something (that's not sand) below it. Then it checks to see if its water. Then it Creates a temporary Sprite to be Passed to the Switch Method if it Is Water. Once that's done It updates the Sprite list Changing it to the Temporary Sprite.

Switch Method:


public void _switch(ContentManager Con, ref _node[,] _grid ,ref _sprite _Sprite)
{
_sprite _Temp = new _sprite(Con,new Vector2(_Sprite._POSITION.X,_Sprite._POSITION.Y),
_Sprite._TYPE,_Sprite._COLOR,_Sprite._ID);
_node _Node = _grid[(int)_Sprite._POSITION.X, (int)_Sprite._POSITION.Y];
_grid[(int)_Sprite._POSITION.X, (int)_Sprite._POSITION.Y] = _grid[(int)_POSITION.X, (int)_POSITION.Y];
_grid[(int)_POSITION.X, (int)_POSITION.Y] = _Node;
_Sprite._POSITION = _POSITION;
_Sprite._ID = _ID;
_Sprite._COLOR = _COLOR;
_Sprite._TYPE = _TYPE;
_POSITION = _Temp._POSITION;
_ID = _Temp._ID;
_COLOR = _Temp._COLOR;
_TYPE = _Temp._TYPE;
}


Fairly straight forward, it takes the Data from the Temporary sprite, and Switches it with the sprite that is currently being processed. Or at least it should, Ive tried 1000 things but when i spawn sand above water it just sits on top. For clarity ive included the game below if you want to see what i mean (Just spawn water then sand above it). All im trying to figure out is WHY they aren't switching, any help is appreciated. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!