Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bissuas

Pages: [1]
1
General / Re: Jumping Sprite triggers after few seconds
« on: April 24, 2012, 05:14:07 am »
OK dude, I will write complete words and sentences from now onwards...Thanks.

2
General / Re: Jumping Sprite triggers after few seconds
« on: April 23, 2012, 07:44:46 pm »
Thank u both for ur suggestion. bcoz i am very new to all these stuffs, ur suggestion means a lot. thanks again.

3
General / Jumping Sprite triggers after few seconds
« on: April 23, 2012, 10:47:32 am »
I am trying to jump my simple sprite and i have written some code but every time when i press up key which is for jumping the sprite sprite jumps after few seconds , is there any solution here is my code please help as soon..Thanks in advance.



using namespace std;

int main()
{
   sf::VideoMode Vmode1(600,400,32);
   sf::RenderWindow Window1(Vmode1, "Project Aasra");
   Window1.SetFramerateLimit(60);
   Window1.UseVerticalSync(true);

   //SECTION START: Images and Sprites

    double x,y,dx, dy;
    x=y=dx=dy=0;

   sf::Image mario2;
   if(!mario2.LoadFromFile("images/mario2.png")){return EXIT_FAILURE; }
   sf::Sprite mario2_sprite(mario2);


    bool hold =true;
    while(hold)
   {
      sf::Event Event1;

    bool space_down=false;
      while(Window1.GetEvent(Event1))
      {
         //window controls
         if(Event1.Type==sf::Event::Closed) { Window1.Close(); hold=false; }
      }

      //SECTION START: direction keys press
      if(Window1.GetInput().IsKeyDown(sf::Key::Right))  dx+=0.5;

      if(Window1.GetInput().IsKeyDown(sf::Key::Left))   dx-=0.5;

        mario2_sprite.SetPosition(x,y);

      x+=dx;
      y+=dy;

    /*friction*/
      dx*=0.775;


    /*jump*/

      if((Window1.GetInput().IsKeyDown(sf::Key::Up)))
      {
        dy=-4.0;
        space_down=true;
      }

      if (!Window1.GetInput().IsKeyDown(sf::Key::Up)) space_down=false;


    /*gravity*/
      if (mario2_sprite.GetPosition().y<252) dy+=0.1;

    /*Screen Limit*/
    if((mario2_sprite.GetPosition().y + mario2_sprite.GetSize().y) > 252)
    {
        mario2_sprite.SetY(252);
    }

      Window1.Clear(sf::Color(0,255,255));
      Window1.Draw(mario2_sprite);
      Window1.Display();
   }
}
 



Pages: [1]
anything