www.xbdev.net
xbdev - software development
Friday March 29, 2024
home | contact | Support | XNA & 360 The bits and bytes of XNA and C# for your 360... | XNA & 360 The bits and bytes of XNA and C# for your 360...

     
 

XNA & 360

The bits and bytes of XNA and C# for your 360...

 

 

Gamepad Vibration!!!  Its only one line of code, and it can make your console app/game so much sweeter.  If you bump into a wall you can do a thud on your game pad, or if you want to give the user a kick, you can just give a quick vibration.

 

There is the left and right rotation motors.  If you run the demo below you can use the left and right thumbsticks to contol there speeds.  And you'll feel that the left motor is a heavy deep rumble, while the right motor is a fast whinny one giving you two completly different effects....but also letting you combine them to creat unique ones!

 

The main function is a member of the GamePad class.  Letting you specify which controller (i.e. which player pad) and the motor speeds.

 

GamePad.SetVibration(PlayerIndex.One, leftMotor, rightMotor);

 

Hopfully you'll be creating unique and exciting things with the gamepad vibration ability!

 

 

Game.cs [Download Full SourceCode]

using System;

using System.Collections.Generic;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.GamerServices;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

 

 

public class GameClass : Microsoft.Xna.Framework.Game

{

    GraphicsDeviceManager graphics;

 

    public GameClass()

    {

        graphics = new GraphicsDeviceManager(this);

    }

 

    protected override void Update(GameTime gameTime)

    {

        //**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**

        //**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**

       

        Vector2 leftThumb  = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;

        Vector2 rightThumb = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right;

        float leftMotor  = Math.Abs(leftThumb.X);  // 0->1.0

        float rightMotor = Math.Abs(rightThumb.X); // 0->1.0

 

        // Move the left and right thumbstick to modify the left and right motor speeds

        GamePad.SetVibration(PlayerIndex.One, leftMotor, rightMotor);

 

        //**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**

        //**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**VIBRATION**

        base.Update(gameTime);

    }

 

    protected override void Draw(GameTime gameTime)

    {

        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        base.Draw(gameTime);

    }

}//End GameClass Class

 

 

// Program Entry Point

static class Program

{

    static void Main(string[] args)

    {

        using (GameClass game = new GameClass())

        {

            game.Run();

        }

    }

}

 

 

Have fun and happy shaking....

 

 

 

 

 

 

 

 

 

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.