Answered Client Rectangle Problem...

PRo-Beaniie

Well-known member
Joined
Mar 17, 2011
Messages
55
Location
Hertford, Hertfordshire, United Kingdom
Programming Experience
3-5
Hey guys,

For a while i have been playing a guessing game with this line of code.

VB.NET:
        If Sdown = True And Shooter.Top >= Me.ClientRectangle.Height Then
            Shooter.top += Shooterspeed
        End If
Basically i have a shooter on the form and whenever i press the down key the shooter moves down the form and disappears off of the bottom of the form. I have been trying to get this to stop for some while but im a little confused with this... Mabye you guys can help :confused:




ANSWERED ..;););) Figuered it out myself ... :)
 
Last edited:
You are checking whether the top of the shooter is below the bottom of the form and, if it is, you are moving the shooter further down. I doubt that that is what you actually want to do.
 
Barrier

i built it so that the shooter cannot escape the form but the shooter does escape the form at the bottom here is the complete code for this.

VB.NET:
 'Shooter Timer Variables ...
        If Sright = True And Shooter.Left + Shooter.Width <= Me.ClientRectangle.Width Then
            Shooter.Left += Shooterspeed
        End If
        If Sleft = True And Shooter.Left >= Me.ClientRectangle.Left Then
            Shooter.Left -= Shooterspeed
        End If
        If Sup = True And Shooter.Top + Shooter.Top >= Me.ClientRectangle.Top Then
            Shooter.Top -= Shooterspeed
        End If
        If Sdown = True And Shooter.Height <= Me.ClientRectangle.Height Then
            Shooter.Top += Shooterspeed
 
Why would you check the Height of the Shooter? That's not going to change. The Height of the Shooter is always going to be less than the Height of the form's ClientRectangle. Think about what it is that you actually care about. It's not the top edge of the Shooter. It's not the height. It's the bottom edge. What property is there that represents the bottom edge? Not surprisingly, it's Bottom.
 

Latest posts

Back
Top