Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Creating new blocks

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 burnt_casadilla   Members   

443
Like
0Likes
Like

Posted 13 September 2013 - 04:26 PM

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, 15 September 2013 - 12:21 PM.

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


#2 DiegoSLTS   Members   

2113
Like
0Likes
Like

Posted 13 September 2013 - 08:05 PM

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.



#3 EarthBanana   GDNet+   

1791
Like
0Likes
Like

Posted 13 September 2013 - 09:25 PM

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



#4 burnt_casadilla   Members   

443
Like
0Likes
Like

Posted 15 September 2013 - 12:17 PM

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 :)





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.