Question Effects

apex

Member
Joined
Feb 28, 2017
Messages
5
Location
UK
Programming Experience
1-3
Hey guys,

I'm trying to make an explosion effect in VB.Net, I already have a gif image on hand for this but I don't know how to go about coding it. I have a collision code and I think it should go somewhere under that but I don't know the code of it. Any help in form of psuedo code will be greatly appreciated.
 
Hey guys,

I'm trying to make an explosion effect in VB.Net, I already have a gif image on hand for this but I don't know how to go about coding it. I have a collision code and I think it should go somewhere under that but I don't know the code of it. Any help in form of psuedo code will be greatly appreciated.
You have an image (gif) and you have code that presumably detects object collision and you need help with pseudo code?
 
I don't know how to set it to read the position where the collision occurs, at the moment it just keeps playing in a loop in the same spot on the canvas.
This the piece of code responsible for the collision:

VB.NET:
 If Ammo.Bounds.IntersectsWith(Intruder.Bounds) Then
            explosion1.Visible = True
            Intruder.Visible = False
            Ammo.Visible = False
            explosion1.Visible = False
            Ammo.Left = 2000
            Intruder.Left = -100
            Intruder.Visible = True
        End If
 
If Ammo.Bounds.IntersectsWith(Intruder.Bounds) Then
    Dim intersection = Rectangle.Intersect(Ammo.Bounds, Intruder.Bounds)

    '...
'intersect' now contains the Rectangle that represents the area of overlap between the two colliding objects.

It's worth noting that the MSDN documentation for the IntersectsWith method that you're already calling includes a code example that does something very similar to this, although it uses another overload of Intersect, so you really should know this already because you should have already read that relevant documentation. ALWAYS read the relevant documentation first.
 
If Ammo.Bounds.IntersectsWith(Intruder.Bounds) Then
    Dim intersection = Rectangle.Intersect(Ammo.Bounds, Intruder.Bounds)

    '...
'intersect' now contains the Rectangle that represents the area of overlap between the two colliding objects.

It's worth noting that the MSDN documentation for the IntersectsWith method that you're already calling includes a code example that does something very similar to this, although it uses another overload of Intersect, so you really should know this already because you should have already read that relevant documentation. ALWAYS read the relevant documentation first.
It's just doing more of the same thing, replaying the image over and over again. I wasn't aware of the MSDN documentation, mainly because our teacher has already set step by step tutorial guides for us to follow, but nothing that contains what I was looking for. I only learnt about the intersect method on this forum because I searched and it came up.
 
I wasn't aware of the MSDN documentation
I imagine that you've been using PC software for some time and, particularly as someone who wants to write software, should not be surprised that VS has a Help menu. As the name suggests, that's where you should go first when you need help. It provides an item to open the MSDN documentation, either locally or on the web.
I only learnt about the intersect method on this forum because I searched and it came up.
That's fine. We all have plenty to learn but, when using a new type or member, it should be a matter of course that you read the documentation for it. Once you knew about IntersectsWith, that would have led you to Intersect.

You're by no means the only person who has ignored the documentation. In fact, most people do. The vast majority of those who do are hindering their own learning though. It's there to help, hence it's being under the Help menu. Some people find it confusing at first, because it's written for all developers, not just beginners, but the best way to get better at using it is to use it. I speak from my own personal experience. I lost count long ago of the number of questions I've answered on forums on subjects new to me simply by reading the same documentation that the person asking the question could have done.
 
Okay so I got it working but I need the image to revert back to the original once it resets to the left of form but it's not.
This is the code I've got at the moment
VB.NET:
If fire1 = True Then
            missile1.Top = missile1.Top - 3
            For i = 0 To 4
                If missile1.Bounds.IntersectsWith(enemies(i).Bounds) Then
                    enemies(i).Image = My.Resources.heli_
                    whichenemy = i
                    missile1hit()
                    enemies(i).Image = My.Resources.explosion2
                    enemies(i).Left = 0
                    enemies(i).Visible = True


                End If
            Next
            If missile1.Top < 0 Then
                missile1.Hide()
                fire1 = False
                missile1.Location = restartmissile.Location
            End If
        End If
 
Firstly, don't keep using My.Resources over and over. Every time you access My.Resources a new Image object is created. What you should be doing is declaring a field and assigning a value from My.Resources to it once and once only, then reusing that field. That way, you don't create multiple copies of the same image.

Also, what's the point of setting the Image to one thing and then to something else a couple of lines later? Only the second will be seen so what's the use of the first?

As for your issue, maybe if you were to explain exactly what you think each line of that code is accomplishing then we could explain what's wrong with it.
 
Back
Top