Grainy photos are usually caused by using a higher ISO setting. In digital cameras, this is referred to as "noise".

Trying to photograph action in a gym is difficult for any camera. There just isn't enough light. If you are shooting at 12X, flash will have no effect and should be turned off.

I would try setting the ISO to 200 and going to shutter priority mode. Then set the shutter speed to about 1/100th of a second. When you hold the shutter button half way down, some cameras will tell you if their is enough light to get a good exposure.

Regardless, take the photo and check the results.
If the photo is too dark you have two choices; raise the ISO setting or slow down the shutter speed.

If the photo had good exposure, you have too choices; raise the shutter speed to better prevent a moving subject from blurring or lower the ISO setting to reduce noise.

You can also try removing the noise with software.
Go to:
and download the free Noiseware Community Edition.
Run the program using the default settings and load your noisy photo.
It should improve the photo.