|
-
Apr 15th, 2005, 11:47 AM
#1
Thread Starter
New Member
Help please!
Hi, i have a game which has many different shapes, but i need to know a bit of code which will be able to tell me how many of those shapes are visible at any time. The shapes become invisible and visible, and i need something which will count up every interval, and display the number.
Thanks
-
Apr 21st, 2005, 12:55 PM
#2
Not NoteMe
Re: Help please!
I'm not too sure what you mean (and i guess others aren't either, since you've got no replies).
I'll describe what i think you mean and tell me if i'm correct.
You have lots of (2D) shapes moving on and off screen.
They can overlap eachother.
They can be visible or invisible.
You want to know if any part of an shapes. can be seen (i.e. its visible and not covered completly).
You want to count the number of these visible shapes.
Is this about right?
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 21st, 2005, 04:57 PM
#3
Re: Help please!
If you have your own user defined type of that shape with a variable called Visible and declared it as boolean, you can use this to your advantage (you'll see). You then check the radius of the shape (using X and Y) and make sure that it's within the screen. Then, declare an array called Shape as that user defined type. Then you cycle through them in a For loop. If it's visible, a counter will increment. Here is what I mean:
VB Code:
Option Explicit
Private Type Shape_Type
'These X and Y positions are based on the shapes
'center
X As Long
Y As Long
Radius_X As Long
Radius_Y As Long
Visible As Boolean
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Shape(100) As Shape_Type
Private I As Long
Private Bounding_Box As RECT
'Then you do some code to make the shapes, and calculate their radius,
etc etc etc. Then right here is where you check if they are visible.
Private Sub Check_For_Visibility()
Dim Counter As Long 'Counter to keep track of number of shapes visible on screen
'Will put a bounding box around the screen.
Bounding_Box.Left = 0
Bounding_Box.Top = 0
Bounding_Box.Right = Form1.ScaleWidth - 1
Bounding_Box.Bottom = Form1.ScaleHeight - 1
For I = 0 to 100
If Shape(I).X + Shape(I).Radius_X < Bounding_Box.Left Then Shape(I).Visible = False
ElseIf Shape(I).X - Shape(I).Radius_X > Bounding_Box.Right Then Shape(I).Visible = False
ElseIf Shape(I).Y - Shape(I).Radius_Y < Bounding_Box.Top Then Shape(I).Visible = False
ElseIf Shape(I).Y + Shape(I).Radius_Y > Bounding_Box.Bottom Then Shape(I).Visible = False
Else
Shape(I).Visible = True
Counter = Counter + 1
End If
Next I
End Sub
Last edited by Jacob Roman; Apr 22nd, 2005 at 08:36 AM.
-
Apr 21st, 2005, 06:11 PM
#4
Not NoteMe
Re: Help please!
Note that Jacob's code only works for rectangles.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 21st, 2005, 06:32 PM
#5
Re: Help please!
Nope. Any shape. Triangles, Circles, Rectangles, squares, etc. The Bounding_Box variable is the screen. It checks if it is within the screen. I used the radius_X and radius_Y of any shape to determine if it's pass the Bounding_Box. If it is then it's not visible. If it's within the bounding box, then it's visible. You should have read my code more carefully.
-
Apr 22nd, 2005, 04:55 AM
#6
Not NoteMe
Re: Help please!
That's all very well, but what would the radius of, say a triangle be?? It varies depending on the rotation of the triangle, so unless you're gonna change it as the shape rotates you're not gonna get 100% results.
I stand by what i said earlier, although it might work for a circle as well.
Also, you've put the Radius_X/Y as booleans, i think you ment Long. :P
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 22nd, 2005, 08:46 AM
#7
Re: Help please!
Yeah, that was a typo. I didn't do that in VB. I was typing whatever was on the top of my head. :P
Ok think of any shape with a circle (or oval for wide/skinny non perfect shapes) wrapped around it. A triangle would be a good example. This is known as a bounding sphere.....errrr actually circle since this is 2D and not 3D. If the circle wrapped around a shape is within the screen, it is visible. If not, then it's invisible.
And no you won't get 100% results, just like in 3D when you are testing all those complex geometric polygonal objects. A bounding box or bounding sphere can only do so much when you are testing them for visibility, but it's close enough to get the job done.
Last edited by Jacob Roman; Apr 22nd, 2005 at 08:49 AM.
-
Apr 22nd, 2005, 10:55 AM
#8
Not NoteMe
Re: Help please!
 Originally Posted by Jacob Roman
Yeah, that was a typo. I didn't do that in VB. I was typing whatever was on the top of my head. :P
Ok think of any shape with a circle (or oval for wide/skinny non perfect shapes) wrapped around it. A triangle would be a good example. This is known as a bounding sphere.....errrr actually circle since this is 2D and not 3D. If the circle wrapped around a shape is within the screen, it is visible. If not, then it's invisible.
And no you won't get 100% results, just like in 3D when you are testing all those complex geometric polygonal objects. A bounding box or bounding sphere can only do so much when you are testing them for visibility, but it's close enough to get the job done. 
I'm well aware of the technique of using bounding boxes / spheres / low-poly objects for this purpose, but i wanted to make clear that as you say, it won't be 100% results.
It'd be usefull if the original poster posted back with what he wanted. :P
We may be way off - he might only want to count those with his .visible tag set to true!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
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
|