Jump to content

  • Log In with Google      Sign In   
  • Create Account


The "Bounce" does not exist in current context


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Thomas Wiborg   GDNet+   -  Reputation: 642

Like
0Likes
Like

Posted 22 January 2013 - 01:59 PM

I currently have following code under my "Game1.cs"
 

 

 protected override void Update(GameTime gameTime)
        {
            
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            Bounce();                                                                        
                      
            base.Update(gameTime);
        }

 

and my "Bounce" method under "GameMechanics.cs"

 

namespace Cannon4
{
    class GameMechanics
    {
        const int SCREEN_WIDTH = 640;
        const int SCREEN_HEIGHT = 480;

        GameItem target;
   
        public void Bounce()
        {
            //Bouncer target vekk fra nordre og søndre vegg
            if (target.Position.Y <= 0)
            {
                Vector2 vecVar;
                Vector2 posVar;
                vecVar = target.Velocity;
                vecVar.Y *= -1;
                target.Velocity = vecVar;

                posVar = target.Position;
                posVar.Y = 0;
                target.Position = posVar;
            }
            else if (target.Position.Y >= SCREEN_HEIGHT)
            {
                Vector2 vecVar2;
                Vector2 posVar2;
                vecVar2 = target.Velocity;
                vecVar2.Y *= -1;
                target.Velocity = vecVar2;

                posVar2 = target.Position;
                posVar2.Y = SCREEN_HEIGHT - target.Origin.Y;
                target.Position = posVar2;
            }
        }
    }
}

 

Why do I get the error "The "Bounce" does not exist in current context"?



Sponsor:

#2 0Circle0   Members   -  Reputation: 342

Like
0Likes
Like

Posted 22 January 2013 - 02:24 PM

At first glance I would say you are incorrectly calling Bounce(). It looks like you're trying to call Bounce() as if it were part of the main program, but Bounce() is inside the class GameMechanics and it is not part of the main class.

 

GameMechanics.Bounce()

 

maybe?


Edited by 0Circle0, 22 January 2013 - 02:29 PM.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


#3 Thomas Wiborg   GDNet+   -  Reputation: 642

Like
0Likes
Like

Posted 22 January 2013 - 02:34 PM

At first glance I would say you are incorrectly calling Bounce(). It looks like you're trying to call Bounce() as if it were part of the main program, but Bounce() is inside the class GameMechanics and it is not part of the main class.

 

GameMechanics.Bounce()

 

maybe?


no thats not the problem. Cause ive fixed it with removing my folder "Classes" which it lies under... So now its a part on main class.

 

 

namespace Cannon4

it WAS
 

namespace Cannon4.Classes


#4 0Circle0   Members   -  Reputation: 342

Like
0Likes
Like

Posted 22 January 2013 - 04:36 PM

If you tried it and it didn't work then I don't know. If you didn't try it then you should.


Edited by 0Circle0, 22 January 2013 - 04:37 PM.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.


#5 Thomas Wiborg   GDNet+   -  Reputation: 642

Like
0Likes
Like

Posted 22 January 2013 - 04:52 PM

Yeah, I tried it :S



#6 Endurion   Crossbones+   -  Reputation: 3423

Like
0Likes
Like

Posted 23 January 2013 - 02:47 AM

Unless your main class (Game1?) is not derived from GameMechanics you can't call Bounce like that.

 

You need a GameMechanics instance somewhere. C# doesn't have class-less functions.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#7 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 23 January 2013 - 04:51 AM

It seems to me you are trying to separate the games event handling from the games content, but you are doing it in a way that convolutes your code in ways you don't want.

Its hard to say though without the complete source.

 

The first thing that strikes me is, why do you have the GameItem inside the GameMechanics class? It doesn't seem right.

 

Another thing that strikes me is that the way the GameMechanics class is now, I would consider making it a static class with static variables/functions.

Then I would put the GameItem somewhere else and pass it as an argument to Bounce.

 

 
class GameItem
{
}
 
static class GameMechanics
{
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;        
 
    public static void Bounce(GameItem target)
    {
        // ...
    }
}
 
class Program
{
    static void Main(string[] args)
    {
        GameItem item = new GameItem();
        GameMechanics.Bounce(item);
    }
}






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS