-
May 25th, 2012, 01:32 AM
#1
Thread Starter
New Member
Load/Unload Object PROBLEM
Hi everyone,
I need help figuring out a way around the Load Object function in my coding. So basically I am making a tetris game where I will load in 4 image boxes at a time. However, after clearing a line, I make these image boxes invisible and place them at .top = 0 and .left = 0 so that they are no longer on the grid. However, after loading many image boxes, the program becomes very laggy and interferes with the game.
So therefore I decided to use the Unload function, but then I get an error in aspects where it will tell me it cannot carry out a procedure because that object is now missing even though I no longer need it. For example:
For IndexNumber = 0 to IndNum
Is there any way around this?
-
May 25th, 2012, 01:35 AM
#2
Re: Load/Unload Object PROBLEM
if object is never loaded then you cannot unload at the beginning of your sub/function
if object is not loaded it will skip
-
May 25th, 2012, 01:51 AM
#3
Thread Starter
New Member
Re: Load/Unload Object PROBLEM
I just tried the On Error Resume Next but it didn't quite work out. Am I placing it in the wrong place? I have it directly underneath For IndexNumber = 1 to IndNum.
Thanks
-
May 25th, 2012, 02:08 AM
#4
Thread Starter
New Member
Re: Load/Unload Object PROBLEM
I think it's also messing up my variables.
-
May 25th, 2012, 05:31 AM
#5
Re: Load/Unload Object PROBLEM
You should be trying to re-use the images rather than constantly adding new ones. You should never create more than can fit on the screen at any one time during a game.
-
May 25th, 2012, 05:36 AM
#6
Re: Load/Unload Object PROBLEM
1) On Error Resume Next doesn't fix the problem it only hides it. So that's not the solution.
2) Since you didn't specify what the error is, or what your code looks like, there's nothing more that we can do to help.
-tg
-
May 25th, 2012, 06:02 AM
#7
Thread Starter
New Member
Re: Load/Unload Object PROBLEM
Originally Posted by ColinE66
You should be trying to re-use the images rather than constantly adding new ones. You should never create more than can fit on the screen at any one time during a game.
That's the problem with tetris. Say the grid has a maximum of 100 spaces. If I do something like this:
If IndNum > 100 Then IndNum = 0
then it still holds the potential that Image1(0) may still be on the grid even after Image1(100) has been placed as I may have cleared all the other image boxes, but Image1(0) has still been left over, and this will cause problems as it will just disappear without it being cleared. That is why the safest coding is to load more in for every piece.
-
May 25th, 2012, 06:08 AM
#8
Thread Starter
New Member
Re: Load/Unload Object PROBLEM
Originally Posted by techgnome
1) On Error Resume Next doesn't fix the problem it only hides it. So that's not the solution.
2) Since you didn't specify what the error is, or what your code looks like, there's nothing more that we can do to help.
-tg
This is basically what's happening:
Code:
For IndexNumber = 0 to IndNum 'IndNum being the index number of the final loaded imagebox
If Image1(IndexNumber).top = 8000 then Unload Image1(IndexNumber) ' to clear the line
Image1(IndexNumber).top = Image1(Index).top + 375 'to move all blocks down 1 line
Next
Basically the error I am getting once Image1(IndexNumber) is unloaded, then the "For" process cannot keep going as there will be a missing object. Is there a way where it can skip that index number if that object does not exist?
-
May 25th, 2012, 06:33 AM
#9
Re: Load/Unload Object PROBLEM
Originally Posted by AndroidMachine
That's the problem with tetris. Say the grid has a maximum of 100 spaces. If I do something like this:
If IndNum > 100 Then IndNum = 0
then it still holds the potential that Image1(0) may still be on the grid even after Image1(100) has been placed as I may have cleared all the other image boxes, but Image1(0) has still been left over, and this will cause problems as it will just disappear without it being cleared. That is why the safest coding is to load more in for every piece.
Well, you have to be smart about how you re-use the images, of course. You can't simply roll-over the number for the reason you mention. I would create a Data Type similar to the following:
Code:
Dim BlocksPerLevel as Integer
BlocksPerLevel= 500 'or whatever
Private Type Block
ImageIndex as Integer
BlockCleared as Boolean
BlockXPosition as integer
BlockYPositon a Integer
End Type
Dim GameBlocks(BlocksPerLevel) as Block
Something like that. Then, once a block is cleared, re-assign a used Image Index to a new GameBlock. Haven't thought the whole thing through - just air-coding but you may get the idea.
Anyway, don't wish to hijack the thread but my point is that performance in your game will be constant since you will always use the same number of images, i.e. the max that can fit on the game board. This is, of course, provided that performance is acceptable at that number.
-
May 25th, 2012, 11:09 AM
#10
Re: Load/Unload Object PROBLEM
For IndexNumber = 0 to IndNum 'IndNum being the index number of the final loaded imagebox
If Image1(IndexNumber).top = 8000 then Image1(IndexNumber).Picture = LoadPicture (""): Image1(IndexNumber).visible = False ' to clear the line
Image1(IndexNumber).top = Image1(Index).top + 375 'to move all blocks down 1 line
Next
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|