Jump to content
  • Advertisement
Sign in to follow this  
ChristianFrantz

Creating new blocks

This topic is 2133 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

Rather than creating a new question I decided to just edit this one:

 

I have an int rotate that holds the rotation for each block. 0 is normal, 1 is clockwise, 2 upside down... I'm able to change the variable by pressing Up on the keyboard, but the block won't change its rotation

private Vector2[] RotateBlock()
        {
            if (Rotate == 1)
            {
                if (Position == LeftLPosition)
                {
                    LeftLPosition[0] = new Vector2(LeftLPosition[0].X + 20, LeftLPosition[0].Y + 20);
                    LeftLPosition[1] = new Vector2(LeftLPosition[1].X + 0, LeftLPosition[1].Y + 0);
                    LeftLPosition[2] = new Vector2(LeftLPosition[2].X - 20, LeftLPosition[2].Y - 20);
                    LeftLPosition[3] = new Vector2(LeftLPosition[3].X - 0, LeftLPosition[3].Y - 40);


                    return LeftLPosition;
                }

This is just the first part of the method but it shows the main picture. 

            if (CheckKey(Keys.Up))
            {
                block.Rotate += 1;
                RotateBlock();
            }

This is in the block update method.

 

I've tried adding a block parameter to the method and using block.LeftLPosition = new Vector2() but that didn't work. I've also moved the line to call the method to different places in the update method and that didn't work either

Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
Advertisement

Maybe you should share more code, there's too little info to give a proper answer.

 

I'm just guessing now, but I think you're problem is that you're blocks are new, but the "sub-blocks" (the Vector2[] that you pass as the first parameter) are being reused.

 

If you're just storing them as an attribute and then changing them to make the block fall try making a copy instead of just assigning, so when the next piece receives the same Vector2[] it won't affect the Vector2[] of the previous block.

 

To get a better answer you should probably explain what do you do with those Vector2[] after you created the Block.

Share this post


Link to post
Share on other sites

Do you have a debugging tool (like msvs2010 debugger)? You can step through your code and see why your "new Block()" call is referencing a block that already exists..

Share this post


Link to post
Share on other sites
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!