Creating new blocks

Started by
2 comments, last by ChristianFrantz 10 years, 7 months ago

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

If you see a post from me, you can safely assume its C# and XNA :)

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.

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..

I figured it out. By using .Clone() I was able to create an infinite amount of blocks. I edited the question tho instead of making a new thread

If you see a post from me, you can safely assume its C# and XNA :)

This topic is closed to new replies.

Advertisement