How Friend Invites work in Spectrangle360

A few #XBLIG #XNA devs have gotten in touch with me over twitter about how I managed to do the "Invite Friend" functionality in Spectrangle360. Although there is an MSDN article on the subject and the XNA gamestatemanagement example shows how this is done I still think a real world example might come in useful for some people.

So I have decided I would explain how I managed to get it to work in Spectrangle360.

Current Structure

Before I dive into the actual code I want to explain a bit about the structure of Spectrangle360 so that the code actually makes sense. Spectrangle360 was developed with the FSM (finite state machine) pattern as a basis, this meant that each of the areas/classes of the game could be split up to handle their own state.

        public interface IState
        void Enter( IStateContext context);
        void Update( IStateContext context, GameTime time);
        void Draw( IStateContext context, SpriteBatch spriteBatch);
        void Exit( IStateContext context);

         public interface IStateContext
        IState State { get; }

        void Update(GameTime time);

        void Draw( SpriteBatch spriteBatch);

        void ChangeState(IState state);

So when Spectrangle360 first starts up the game enters into a "GameS

creenManager" state which inherits from "IState", this "GameScreenManager" state is the main state of the game which is always running unless the game throws any exceptions. From this state other states are entered eg when the Demo is playing, the game is playing or the game is being played via Xbox live and this state "TwoPlayerLobby" is the class that handles all the work when a players is in the lobby trying to create or join a two player game.

The Code

The first piece of code is the code which I used to basically set up some variables and to hook the "InviteAccepted" event :-

    public void Hook(SpectrangleManager manager, GameScreenManager gm, bool hook)
            _mgr = null;

            _mgr = manager;

            _gsm = null;
            _gsm = gm;

            _context = gm;

            if (!hook)
                NetworkSession.InviteAccepted += NetworkSession_InviteAccepted;

This hook code is called from the "MainScreen" state via its enter method like this, "_TPL" is an instance of the "TwoPlayerLobby" class :-

    public void Enter(IStateContext context)
                ((GameScreenManager)context)._TPL.Hook(((GameScreenManager)context).Manager, (GameScreenManager)context, ((GameScreenManager)context).AcceptHook);


Having an instance of the "TwoPlayerLobby" class means that the game is always ready to accept invites when the player is in the "TwoPlayerLobby" state.

The code used once a game invite has been accepted is this :-

    public void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)

            Game1.HSC.SearchNetworkOff = true;
            Game1.HSC.Enabled = false;

            _gsm.GameSearch.Disable = true;


                // stops a different gamer controller joining a game in progress
                if (e.Gamer.PlayerIndex != Game1.Global.Controller())
                    _gsm.ChangeState(new NetworkErrorMessage("You cannot join game in progress with a different gamer. Please return to the title screen if you wish to swap profiles."));

                // Quit the current session
                if (_mgr.Session != null)
                        _mgr.Session = null;

                // We can now create a new instance of the SpectrangleManager game and then create the player instances to be used later.

                _gsm.Manager = new SpectrangleManager( Game1.Global.Content, (GameScreenManager)_gsm);

                _mgr = _gsm.Manager;

                _mgr.Players[0] = new Player(_mgr, PlayerIndex.One, "1", PlayerSide.WHITE, false);
                _mgr.Players[1] = new Player(_mgr, PlayerIndex.Two, "2", PlayerSide.BLACK, false);

                    // Join the new session
                    _mgr.Session = NetworkSession.JoinInvited(1);
                    _gsm.ChangeState(new NetworkErrorMessage("Unable to join game in progress."));

                // hook the normal network session events

                // We can change the state to wait for the host to start as we have now accepted the friend invite
                _gsm.ChangeState(new WaitForHostToStart(2, false, _mgr,_mgr.Session));

And there you have it, this code allows friend invites to be accepted and once the invite is accepted the "GameScreenManager" main state is changed to "WaitForHostToStart" state. Yes I know this could have been done much cleaner but I just wanted to get this to work the easiest way I could at the time. If I ever develop another multiplayer game with Xbox Live friend invites I would probably look at this whole code again to see if I could improve it.

Anyway hope it helps some one.


I blog with BE Write

Using SpriteVortex to create animations

The other day whilst experimenting with some projects I started looking round the web to see if there was a tool I could use to extract a Spritesheet I could use in XNA from an image which had number of different animation frames.

Well I couldnt find anything that exactly did what I wanted but I did find a little app called SpriteVortex. 

This app seems to be able to scan an image and pick out the frames of your image using a colour key and construct a list of sprites. The app then lets you construct a list of animation sets which you can add each sprite too and it even has a little animation preview window where you can offset each frame to get them to animate correctly and set the animation time for each frame.
When you have done with your animation you can then export the whole thing to an XML file.

This all sounded good however I couldnt seem to find a way use this XML to generate animation in my own XNA project. So I got to thinking how I would do it. Well as the XML is simply XML I thought I might be able to write my own XML deserializer to read in the XML and construct the sprite and animation objects from the data.

After doing a bit of reading round on serializing and deserializing I came up with this cs file :-

namespace SpriteVortexDeserialize
    public class Sprite
        public string Name;
        public int Id;
        public Coordinates Coordinates;
    public class Coordinates
        public int X;
        public int Y;
        public int Width;
        public int Height;
    public class Animation
        public string Name;
        public int FrameRate;
        public string Loop;
        public string PingPong;
        public List<Frame> _frames;
    public class Frame
        public int SpriteId;
        public float OriginX;
        public float OriginY;
        public int OffSetX;
        public int OffSetY;
        public float Duration;
    public class Texture
        public string Path;
        public string Name;
    public class SpriteMapping
        public Texture texture;
        public List<Sprite> _sprites;
        public List<Animation> _animations;
Once you have this class you can then deserialize the XML into this object structure using this code :-

SpriteMapping spriteMapping = new SpriteMapping();
XmlSerializer serializer = new XmlSerializer(spriteMapping.GetType());
TextReader textReader = new StreamReader("./Content/testknight.xml");
spriteMapping = (SpriteMapping)serializer.Deserialize(textReader);
As usual you would have to put your image assets and your XML into the Content project however you have to set the XML file to ContextProcessor = "No Processing Required" and Copy to Output Directory = "Always Copy".

Hope this helps somebody out who wants to use this little app without writing your own sprite manager functionality, also if I get some feedback on this post I might also upload a sample project but havent decided that yet.

More reviews

More reviews,

We got another review from @IndieGamerChick, to be honest we were quite worried about the review as in the past IndieGamerChick had found the issues relating to the multi player part of the game and she is also known for her very ... how can I say cutting remakes.

To be fair I am actually quite happy with the review, she tells it how it is, which I can safely say is better then some of the reviews I got which just moaned about the music... She also actually ranked us 83rd on here 100 leader board. Anyway here is the link.

Indie Gamer Chick reviews Spectrangle360


First update

Spectrangle360 - Update 1

So it’s almost been 4 months since Spectrangle360 went on to the Xbox Live indie marketplace and the first update for Spectrangle360 has finally passed the review process.

Why do an update?

I have asked this question to myself several times and haven’t come up with a good answer, the best answer I have is that personal pride made me do it. If I was doing this for the money I would certainly not sell enough versions of Spectrangle360 to make up for the number of hours I have ploughed into this game.  

The problem

Basically Spectrangle360 worked, it worked very well if I do say so myself having been the first indie game I have ever released. But there was some very annoying issues being seen when playing Spectrangle360 over Xbox Live in the wild. Now most indie games don’t include multiplayer over Xbox Live and they don’t include it for 1 reason... complexity. Now I am not using this as an excuse, developing an Xbox Live game on your own and being able to test all online scenarios is almost an impossible task. This meant on the release of Spectrangle360 people had synchronization problems and disconnection problems which meant playing online was basically pointless.  

Update Fixes

My first mission was to remove these synchronization issues from the game and to also fix some other small problems on the way if given time. Well after 4 months I think I have achieved this goal. Here is a list if the issues the update hopes to fix.
  • Multiplayer synchronization issues when playing and rotating pieces. 
  • Adding a new score board to record and display online games vs humans. 
  • Added "Invites" to allow people to invite their friends and join peoples lobbies. 
  • Pausing whilst playing online. 
  • Improving the score screen to allow players to compare stats against cpu and humans. 
  • Being able to change the music straight away. (Still need to get more tracks) 
  • Improving the credits screen "QR-code" to allow people to navigate to our website easier (hoping for some more player feedback).  

I am hoping these changes both restore my reputation on the indie scene plus I am hoping a lot more people play the game online now. Most of all I can rest happy knowing these I managed to fix these issues all the while dealing with everyday life (maybe more on this some time). I am also thinking about setting up some sort of league to play online but I guess I would only do this if I know people read this blog and participated, it would be good to play some the 200+ people that have purchased the game.

I guess we will see what happens...


1 Week on #XBLIG ....WOW


Its been over a week of being on Xbox360's indie Xbox Live channel and man its been busy. Busy? what do you mean busy? I hear you say, well if you want to get some decent sales on Xbox Live the first few weeks are the most important I feel. You really have to try hard to get your game known as much as possible before the game slips down into the recent published list. So to get my name and Spectrangle360 out there I have been emailing and tweeting/retweeting as much as possible, below is a list of hopefully all the reviews I have managed to get so far. Most of the them think that Spectrangle360 is a good game but limited to the board game enthusiast, which to be honest I was expecting any way here's the list. Hope I didn't miss any and if I did...sorry:-

To those that helped me with these reviews I want to say thanks, I specially want to thank @DaddyPigGames and @MayContainGeeks you should look these guys up on twitter there great :).

So whats next, well I plan to do an update to Spectrangle360 from the things I am not happy with myself and a few issues but more on that in another post. I hope to keep Spectrangle360 in the lime light as it where for as long as possible and just build on what I have already done so far.

And if you have bought Spectrangle360 I just want to say a BIG THANKS.

Your awesome, also let me know what you think of the game and what you would like improving.


Spectrangle360 now on the marketplace

Hi, Well for once MS have been quite responsive. When I pushed the "Publish Now" there is a warning saying it could take upto 24 hours. So I thought that if worst came to the worst I should press the button today at around 12pm in hopes that the game will be available Friday (23/3/12). Well the game actually published in 2 hours...this was the fastest part of the process, anyway here it is.

Offically an Xbox360 indie developer

Finally.....FINALLY I managed to get Spectrangle360 past peer review and I am now able to publish it to the Xbox indie market place.

It wasnt an easy ride by any stretch of the imagination, after entering playtest on 9/11/2011 and submitting the game 17 times and then starting the review process on 1/12/2011 and submitting 8 times I finally got the 8 passes I needed.

So whats next, well the next step is to finally press that "Publish Now" button, my initial plan is to do this on the 23/3/2012 so that the game will be available the next day (Friday) hopefully. Mean while I plan to use all the contacts that I have made over the months to get the word out about Spectrangle360 and hopefully build a little interest before the game is available.

Theres plenty of things to do, wish me luck.....

Highscores Component XNA v4.0

Highscores Component XNA v4.0

A while ago I downloaded Jon Watte's Highscore Component. However after using it for quite some time it became apparent that I had to convert this to work in the new XNA v4.0.

So I did this work, I cant say how well I converted it but it seems to work for me. If you would find this useful heres a link to the CS file. You will have to pull this CS file into your project and change the namespace to match the name of your games namespace. Hope it helps someone in some way.



More review\playtests, new contacts & paying it forward

Well after pulling Spectrangle360 from playtest then putting it into review then pulling the game and putting it back to playtest rince and repeat at least 2 more times I now have more of a feeling how the XBLIG review\playtest process works.

The most difficult aspect of it all is to get enough people interested in your game that people will use their own time to download your game, playtest it and post comments on the thread with any issues they find. Even harder is once you think you have fixed all the issues you then have to get enough passes in order that your game passes review and then gets published to Xbox Live.

So where am I up to so far? Well after finding some more contacts and paying it forward (in other words trying to do as many playtest\reviews as possible in hopes that some people will feel obliged to return the favour). I got some quite good feedback, the main feedback was to remove the high score sharing code as this at the moment is very problematic and would take to long to fix for the first version. I have also replaced the high score sharing with an online game notification system.

So when some one starts playing Spectrangle360 online anyone else playing the game at the same time will get notified and then have the option to join the game. I will test these features as much as possible and put the game into playtest again for a week and then try and drum up some playtests.