Advertisement

slider control

Started by October 28, 2024 09:03 PM
0 comments, last by pbivens67 1 month, 2 weeks ago

I am trying to implement a slider control in a tank game to adjust the bullet trajectory.

here is the code I am working on.

			SDL_Event e;
			int sliderValue = 50;
			int sliderX = 100;
			int sliderY = 200;
			int sliderWidth = 200;
			int sliderHeight = 20;

			bool quit = false;

			while (quit == false)
			{
				while (SDL_PollEvent(&e))
				{
					if (e.type == SDL_QUIT)
						quit = true;

					if (e.type == SDL_MOUSEBUTTONDOWN) 
					{
						if (e.button.button == SDL_BUTTON_LEFT) 
						{
							int mouseX = e.button.x;
							int mouseY = e.button.y;

							if (mouseX >= sliderX && mouseX <= sliderX + sliderWidth &&
								mouseY >= sliderY && mouseY <= sliderY + sliderHeight) 
							{
								sliderValue = (mouseX - sliderX) * 100 / sliderWidth;
							}
						}
					}
				}

				// Draw the slider track
				SDL_Rect rect_four;
				rect_four.x = 800;
				rect_four.y = 600;
				rect_four.w = 200;
				rect_four.h = 20;
				SDL_BlitSurface(gHelloWorld_four, NULL, gScreenSurface, &rect_four);
				SDL_UpdateWindowSurface(gWindow);

This topic is closed to new replies.

Advertisement