7 Replies - 863 Views - Last Post: 01 June 2016 - 06:41 AM Rate Topic: -----

#1 LongDong123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-May 16

Need help Tagging.

Posted 31 May 2016 - 05:30 AM

Trying to make a frogger game although I don't want to have a separate line of code for each Log or body of Water

Example of what I have:

[If picFrogger.Bounds.IntersectsWith(picLog1.Bounds) Then
ElseIf picFrogger.Bounds.IntersectsWith(picLog2.Bounds) Then
Else
Call EndGame()]

I've looked at some explanations online about tagging but i cant seem to find a correct way, i am always getting errors that crash the program (eg. Object reference not set to an instance of an object.)

First game so still learning

Any help is appreciated thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Need help Tagging.

#2 Recoil   User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Re: Need help Tagging.

Posted 31 May 2016 - 06:23 AM

You are probably going to have to provide more information about what you are trying to do because "tagging" can have several meanings.

The object not being set - you are probably not initializing stuff properly first before your game loop...if you have one at all.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14158
  • View blog
  • Posts: 56,748
  • Joined: 12-June 08

Re: Need help Tagging.

Posted 31 May 2016 - 06:52 AM

Presumably you would have a collection of game objects.

Oh, and stop using picturebox objects. There's a mess load of bloat and kruft with those. A simple bitmap object and rectangle object in a class should work.
http://www.dreaminco...-basics-part-1/
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6561
  • View blog
  • Posts: 26,611
  • Joined: 12-December 12

Re: Need help Tagging.

Posted 31 May 2016 - 10:58 AM

Note that square brackets are not code tags:

Attached Image
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: Need help Tagging.

Posted 31 May 2016 - 01:20 PM

Below is a link to another small snippet that you can read and test real quick which is a basic example of using a Bitmap image and a Rectangle to draw and move a game character. You should also note that i mention the game characters and objects should be a class or a few classes all to themselves. These classes are what you would keep in a collection which modi123_1 mentioned.

Drawing and moving a game sprite image on a form

This post has been edited by IronRazer: 31 May 2016 - 01:41 PM

Was This Post Helpful? 0
  • +
  • -

#6 dday9   User is offline

  • D.I.C Regular

Reputation: 95
  • View blog
  • Posts: 495
  • Joined: 17-April 13

Re: Need help Tagging.

Posted 31 May 2016 - 01:25 PM

I think that I follow you when you mention Tagging; when you say tagging do you mean the process of giving controls a certain tag to essentially group them together? If so then presumably you're creating the controls dynamically. When you create the controls give them their desired tag value(I'll use 'log' in my example) and then use something like the following:
Dim hitLog As PictureBox = (From log As PictureBox In Me.Controls.OfType(Of PictureBox) Where log.Tag IsNot Nothing AndAlso log.ToString() = "log" AndAlso log.Bounds.IntersectsWith(picFrogger.Bounds)).FirstOrDefault()

If hitLog IsNot Nothing Then
    'End game
End If

Was This Post Helpful? 0
  • +
  • -

#7 LongDong123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-May 16

Re: Need help Tagging.

Posted 01 June 2016 - 06:20 AM

Yea that's exactly what I mean. I tried your code and playing around with it but it's not yet working, here's what I have.

Sub CheckCollision() 'Checks for collision'  

        'Log Tag'
        Dim hitLog As PictureBox = (From log As PictureBox In Me.Controls.OfType(Of PictureBox)() Where log.Tag IsNot Nothing AndAlso log.ToString() = "log" AndAlso log.Bounds.IntersectsWith(picFrogger.Bounds)).FirstOrDefault()

        If hitLog IsNot Nothing Then
            Call EndGame()
        End If





What am i doing wrong?

ps: beginner

This post has been edited by andrewsw: 01 June 2016 - 11:24 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#8 dday9   User is offline

  • D.I.C Regular

Reputation: 95
  • View blog
  • Posts: 495
  • Joined: 17-April 13

Re: Need help Tagging.

Posted 01 June 2016 - 06:41 AM

What isn't working? I actually free-typed the code because I'm not at a computer with Visual Studios installed on it so I'm not able to do any debugging. Are you receiving an error? If not whenever you setup a breakpoint on the conditional statement, what is the value of hitLog?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1