Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

24. April 2012

 

 

There is a charter somewhere that states all tutorial series must start with the ubiquitous Hello World tutorial, and who am I to break the charter?  So that is exactly what we are going to do here, a simple Hello World. This is as much about getting up and running with PS Studio than it is about C# coding, as there are a couple small gotchas.  By the end of this tutorial you should be able to create, configure and run an application.  In future tutorials, I will assume you have these abilities.

 

If you haven’t already, download and install PlayStation®Suite SDK from here.  The install is pretty straight forward, take the defaults, next next next, done.  If you want some idea of what you just installed check out this post.  Now fire up PssStudio from your start menu.  Once loaded, select File->New-Solution, like this:

 

image

 

 

In the “New Solution” dialog, on the left hand side expand C# then select PlayStation Suite.  Select PlayStation Suite Application on the right, then fill in whatever name you want ( I  am using HelloWorld ).  This should automatically fill in Solution Name, it is your choice if you want to create a subdirectory or not, in this case I will.  Fill out the dialog like this:

 

image

 

 

Click OK, and your solution will be created.  Now we need to add an app.cfg file to your application, or it will fail to run.  Note, this is not that same as a .NET application configuration file.  In the Solution Explorer, right click your project name ( HelloWorld in my case ), then select Add->New File… like such:

 

 

image

 

 

Choose Misc on the left, then Empty Text File, name it app.cfg and click New.

 

image

 

The newly created file will open in the text editor, fill it in with the following:

 

memory: resource_heap_size : 16384 managed_heap_size : 16384 input: gamepad : false touch : false motion : false

 

 

This file is telling what kind of machine your application is targeting.  If you forget this step, the simulator pss.exe will just max out a CPU core, never responding.  Now in the Solution panel, locate and double click AppMain.cs, this is where our application code will reside.

 

image

 

 

The actual process of doing Hello World on Vita is actually incredibly involved, as you need to do almost everything yourself.  In this example however, I am going to take advantage of GameEngine2D, which is an included 2D Game engine that makes many of the drudge worthy tasks much easier.  That means we need to add a reference to GameEngine2D.  Adding a reference is simply saying “I am going to use the code included in this library” In order to add a reference to GameEngine2D, right click on References and choose Edit References… like such:

 

image

 

Then a dialog will pop up, locate Sce.Pss.HighLevel.GameEngine2D and check the box to it’s left.  Then click OK.

 

image

 

 

Now we can add a using entry to tell our code to use the newly referenced library.  This is where we run into a bug in MonoDevelop ( PS Studio ).  Look at the following auto-completion screenshot:

 

image

 

 

Hmmm… where is HighLevel?  We added the reference, it should be there.  Well, on adding a new reference it seems the intellisense/auto-completion isn’t updated properly.  I live by auto-complete so this is a big deal to me.  Simply close and re-open your solution and presto:

 

 

image

 

 

Thankfully, you don’t really need to add references all that often, so while it’s inconvenient to have to exit and restart, its not the end of the world.  PS Studio loads quickly enough to barely notice.

 

 

Alright, finally time for the code!

 

 

using System; using System.Collections.Generic; using Sce.Pss.Core; using Sce.Pss.Core.Environment; using Sce.Pss.Core.Graphics; using Sce.Pss.Core.Input; using Sce.Pss.HighLevel.GameEngine2D; using Sce.Pss.HighLevel.GameEngine2D.Base; using Sce.Pss.Core.Imaging; namespace HelloWorld { public class AppMain { public static void Main (string[] args) { Director.Initialize(); Scene scene = new Scene(); scene.Camera.SetViewFromViewport(); var width = Director.Instance.GL.Context.GetViewport().Width; var height = Director.Instance.GL.Context.GetViewport().Height; Image img = new Image(ImageMode.Rgba, new ImageSize(width,height), new ImageColor(255,0,0,0)); img.DrawText("Hello World", new ImageColor(255,0,0,255), new Font(FontAlias.System,170,FontStyle.Regular), new ImagePosition(0,150)); Texture2D texture = new Texture2D(width,height,false, PixelFormat.Rgba); texture.SetPixels(0,img.ToBuffer()); img.Dispose(); TextureInfo ti = new TextureInfo(); ti.Texture = texture; SpriteUV sprite = new SpriteUV(); sprite.TextureInfo = ti; sprite.Quad.S = ti.TextureSizef; sprite.CenterSprite(); sprite.Position = scene.Camera.CalcBounds().Center; scene.AddChild(sprite); Director.Instance.RunWithScene(scene); } } }

 

 

PHEW!  Pretty long for a Hello World eh?  Truth of the matter is, had I not used GameEngine2D it would have easily been 4 or 5 times longer!  We will cover what is going on behind the scenes ( the stuff GameEngine2D is handling ) in a later post.  For now, just assume this is the way it works, at least while you are getting started.  Now lets take a quick walk through the code and look at what’s happening here.

 

First we add our additional includes, Sce.Pss.HighLevel.GameEngine2D and Sce.Pss.HighLevel.GameEngine2D.Base.  Our app consists of a single method, Main, as the event loop is actually managed by the Director.

 

Speaking of which, that is what the first line does, initializes the Director singleton.  A singleton is a globally available object that is allocated on it’s first use.  Director is the heart of your game, even though most of the complexity is hidden away.  Remember, you have full source code for GameEngine2D available if you want to peek behind the curtain.

 

Next up we create a Scene.  Again, Scene is an abstraction provided by GameEngine2D which can be thought of as a collection of visible “stuff”, the bits and pieces that compose what we want to display to the user and the Camera used to display them.  We then call SetViewFromViewport() which creates a camera sized to the window. Generally without GameEngine2D, you would have to do this yourself, setting up an orthographic project.

 

The next two lines get the width and height, as reported by the Director’s OpenGL context.  We then create an Image the same dimensions as our viewport.  The Image class is used to hold binary image data, such as from a PNG or JPG file, but in this case we are create a new blank image.  Once we create our Image, we call it’s DrawText method to draw our “Hello World” message.  ImageColor represents the color we want to draw the image ( red in this case ), Font represents the font to draw the text in ( there aren’t really many options here ), while ImagePosition represents the location within the image to draw the text at.

 

Now that we have created an image, we need to create a texture out of it.  Textures are most often thought of as the images mapped around 3D objects and in a way, that is still what we are doing here.  GPUs have no concept of image files or pixels, they deal only with textures.  That is why we copy our image data into the texture, using the SetPixels method of Texture2D and the ToBuffer() method of Image, to turn the images pixel data into an array Texture2D can use.  At this point we are done with our Image, so we Dispose() it.

 

We next create a TextureInfo object and assign our newly created Texture to it.  TextureInfo caches UV location information about the texture, as well as taking ownership of the texture itself.  More importantly, it’s a TextureInfo object that Sprite expects, so that is what we create.  Speaking of sprite, that is what we create next in the form of a SpriteUV.

 

Since modern GPUs don’t really deal with pixels anymore, everything is pretty much made out of textured polygons and SpriteUV is no exception.  It is essentially a rectangular polygon that faces the camera with our image textured on it, all sprites are.  Next up we set the sprite’s Quad ( the rectangle the texture is plastered to ) to be equal to the size of our texture, which in this case is the same size as our view.  We now position our sprite smack in the middle of the view.

 

Now that we created our Image data, copied that image data into a Texture2D that was then assigned to a TextureInfo object, which in turn was assigned to a SpriteUV, we are now ready to add that fully textured sprite to our scene, which we do by calling AddChild().  Yeah, it sounds very convoluted, but you will find it natural very soon and generally you just load your textures from file anyways, greatly simplifying this process.

 

Anyways, now that we have our scene populated with our texture, which is the same size as the screen, we go ahead and tell the Director to do it’s thing, via RunWithScene().  You can think of this as the game loop, although the internals of what it’s doing are hidden from you.

 

 

Don’t worry, it’s really not as complicated as it seems.  Now lets take a look at the fruits of our labour.  To run it in PS Studio, select the Run menu and either choose Start Without Debugging or Start Debugging, depending if you want to be able to debug or not, like such:

 

image

 

 

And presto, all our hard work resulted in…

 

image

 

May not be much to look at, but you successfully created a game you can run on a Vita!

 

Speaking of which, if you need details of running on an actual device instead of in the simulator, read this post.

 

The complete project file for this tutorial are available for download here.

 

 

 

Continue on to Hello World Part 2: Hello Harder.

Programming , , ,

23. April 2012

 

 

Photoshop has always been the big boy in the 2D imaging world and I have always found it a bit too expensive at the @ 800$ a license.  What would you say though if you could insteadimage buy Photoshop CS on a subscription basis for 50$ a month?

 

How about if I threw in some cloud based features like online storage?  Still not sold?

 

Ok, how about if I threw in Photoshop Touch as well?  Still not convinced?

 

Oh, how about I threw in say… Illustrator, Lightroom, InDesign, Muse, Acrobat Pro, Flash Pro, Flash Builder Premium, Dreamweaver, Edge, Fireworks, Premiere, After Effects, Audition, SpeedGrade, Prelude, Encore, Bridge, Encoder, Proto, Ideas, Debut, Collage and Kuler?  Did that get your attention?

 

 

Because that is exactly what Adobe just did!

 

 

The newly announced Creative Cloud appears to be a an all you can eat subscription to pretty much everything Adobe makes, coupled with their fairly new web services, like 2GB of cloud storage.

 

Pricing starts at 50$ on a annual commitment basis, rises to 75$ on a month by month basis.  If you are already paying for one or more CS products, this represents a massive discount.  Oh, speaking of already paying, if you are an existing subscriber, it is available until August 31 at 30$ a month!.

 

 

 

Tempted yet? Winking smile

 

 

 

EDIT: I suppose I should point out, you can’t actually buy it yet, its in pre-order at the moment. 

General, Art

22. April 2012

 

 

This post is going to take a look at what’s included with the PS SDK, PlayStation Suite Studio and all the various included tools and tutorials.  So if you are wondering what is included in the PSSDK or have downloaded it and are trying to figure out what exactly you’ve got, this post is for you!  It assumes you’ve installed to default directories, so if you haven’t you have to adjust all locations accordingly.

 

 

image

 

 

Where is everything?

 

 

The PS Suite SDK installs to two different locations.  First check out

C:\Users\Public\Documents\Pss

This is where all the documentation and samples are installed.  The samples are amazingly comprehensive, but we will cover that later.  The samples are in the “samples” sub-directory.  The documentation are in the “doc\en” sub-directory.  The most important file is pss_sdk_doc_e.chm, which is the primary source of documentation and should soon become your best friend.  On the other hand “index.html” brings up the html document, which appears to be system generated class reference documentation and duplicates a lot of the information in the chm file.  Of course, both of these can be launched from the start menu.  Just do yourself a favour now, open pss_sdk_doc_e.chm now and leave it open! Winking smile

 

 

The next important folder is C:\Program Files (x86)\SCE\Pss, assuming you are running a 64 bit Windows ( drop the (X86) if not ).  The mono and software directories can be pretty much ignored.  Within the “target\win32” is pss.exe, which is the PlayStation Suite simulator which of course can be launched from Studio.  The source directory contains 4 helper libraries with full source code, GameEngine2D, Model, Physics2D and UI.  Most are documented in the main documentation already, so I won’t go into further details on these.

 

Perhaps most important is the tools sub-directory and the key files being:


 

adb This is the Android debugging bridge, it’s normally part of the Android SDK, but apparently PSS uses it for debugging too.

AnimationConverter This command line application is used to convert animations authored in Adobe Flash into a PS Suite compatible format.

OscCustomizeTool This tool is used to create onscreen joystick controls for Android ( but not the simulator or Vita ).  The output is a cfg file.

PssStudio This is where the Studio is located, which is a customized version of MonoDevelop and we will see it in more details later.

ModelConverter Is a command line utility to convert from dae, fbx, xsi and x formats to mdx format for use in PS Suite, I will cover this process in an upcoming tutorial.

Vita This folder contains the device driver needed for your computer to see your Vita.

ShaderConverter Used to convert cg shaders to a PS compatible formats.

UIComposer Used for making GUIs, will look at this in a bit more detail later

 


 

Playstation Suite Studio

 

 

This is where the magic happens.  PlayStation Suite Studio is a modified version of MonoDevelop, which is a code editor, project manager and debugger all in one.  You create, debug and compile your code all from within Studio, which is capable of launching the Simulator or deploying and debugging on your actual device.  This is as screenshot Studio in action:

 

image

 

On the left is the project manager window, to the right is the tabbed area where you edit or debug your source code.  The windows change based on your current activity.  Perhaps the most important modifications to MonoDevelop, are the new PlayStation Studio specific projects.

 

image

 

Until the Visual Studio add-in is released, PlayStation Suite Studio is where you are going to spend the majority of your waking hours.  I will cover parts of it in more detail in later tutorials.

 

 

 

PlayStation Suite UI Composer

 

 

UI Composer is where you put together your User Interfaces, which are then saved in .uic XML format.  If you are familiar with building UIs in Visual Studio, Interface Builder, Qt Designer or various other similar UI generators, you will feel right at home here.  Here is a shot of UI Composer in action:

 

image

 

 

There’s a pretty good selection of widgets available, illustrated below:

 

image

 

 

UI Composer can be used to generate Scenes, Panels, Dialogs and ListPanels.  Once you have drawn your UI, you then “Build” it, which then generates cs code to be included in your project.  The code generated uses partial classes, meaning you can add your code, but if you make changes, it will not overwrite them.

 

 

 

OscCustomizeTool

 

 

This is a neat tool for creating onscreen controls for Android tablets.  The end result is a cfg file that controls how the, um, controls will be created.  However it doesn’t work on Vita ( makes sense… ) and doesn’t work on the simulator ( doesn’t make sesne ), so I haven’t really got a chance to use it.  The UI seems quite evident though, you pick what capabilities to enable:

 

image

 

 

Then you select the layout and form factor you want to use:

 

image

 

I look forward to trying this out a bit more, so hopefully they will add compatibility with the simulator, even if just single touch at first ( or better yet, give the ability to remote control using a device, or map to a keyboard ).

 

 

The Demos

 

 

Ok, wow, this is the part Sony really got right.  There are full source code demos, many many many demos.

 

 

As to the demos, there are lots of little ones you would expect to demonstrate individual aspects, such as playing music, math usage, clipboard, storage, networking, physics, input, UI, model loading, imaging, etc.  Then some are extremely impressive and detailed, like the following:

 

 

A flight game:

image

 

 

A Arkanoid-ish Game:

image

 

 

A 3D Tower defense game:

image

 

 

A fully 3D RPG!

image

 

 

A 3D R-Type style game:

image

 

 

An Angry Birds Style game:

image

 

 

A 2D Side Scroller:

image

 

 

A Puzzle Game:

image

 

 

An RSS Reader:

image

 

 

And many more.  Seriously Sony, bang up job on the samples!  This is where you will spend a lot of your time, reading through the source examples, which I need to warn are often documented in Japanese, as are some of the tooltips.

 

 

The SDK

 

So that’s the tools and demos included, what about the actual code libraries themselves?  Well, PlayStation Suite SDK is based on Mono, so you get most of the libraries you would expect from it, which means most of the .NET runtime which is pretty comprehensive.

 

Additionally, as I mentioned earlier, they provided full sample projects, including a 2D Game Engine and a physics implementation.  On top, here is the class hierarchy of the current SDK:

 

 

 

ClassListPS

 

Over all, I am extremely impressed with what is included.  I wish Visual Studio support was ready, but PlayStation Studio (MonoDevelop) is pretty impressive if a bit sloppy at times.  You basically have everything you need to get started, it’s just a matter of finding it.

 

 

In a nutshell, that’s what you get when you install PlayStation Suite SDK. If you are just starting out, I highly recommend you jump into the CHM help file, or more importantly, start running through the samples.  There is a ton of great content in there and they have been my main source of information so far, as the documentation can be a bit… lacking at times.

General , , ,

21. April 2012

 

 

 

Over on the PlayN Google group PlayN 1.2 has been announced.  I have checked and it is up on Maven, although you need to click “Include snapshot archetypes” to find it.  To get started you can follow this install guide using these settings:

 

 

image

 

 

As to what’s actually new?

 

- You can now listen for mouse and pointer events directly on layers.
- Ray brought the Flash backend up to date. Christopher &co at
King.com shipped an awesome Facebook game using it.
- There's an experimental GL20 interface that allows you to make
OpenGL calls directly. It works on Android and WebGL.
- Image.subImage relieves you from having to roll your own image tiling code.
- The iOS backend is almost entirely done. There's an ios submodule in
the new Maven archetype. A getting started guide is still needed.
- Check the release notes for all the other awesome improvements, both
large and small.

In addition to playn-1.2, I have also released tripleplay-1.2 for your
user interface creating pleasures (along with a grab bag of other
useful things)

 

 

Flash and iOS maturing are both great news, and direct access to OpenGL are sure to be useful features.  More details of what’s new can be found in the release notes.

News

21. April 2012

 

 

I am really enjoying the PS Suite and compared to the Android emulator, the PlayStation Suite Simulator is extremely fast, but also extremely limited.  Perhaps most annoying, the joystick is actually handled using the keyboard.  I had sort of pictured being able to plug in a joystick on my development PC, but sadly this isn’t true.  Hopefully this is a feature they will add soon.

 

 

So, long story short, I went out today and picked up a PS Vita, so expect to see a series of tutorials after all! Winking smile

 

 

First thing I encountered was the process of getting debugging working on device.  It’s not actually that difficult, just a bit non-intuitive, so I figured I would document the process here.

 

 

First I assume you have installed the PlayStation Suite Studio already.  Be sure that you install the USB driver at the end of the install process.

 

 

Now on your Vita, open Browser and navigate to http://www.playstation.com/pss/developer/openbeta/index_e.html and click the PlayStation Suite Development Assistant download link like such:

 

2012-04-21-143816

 

 

You will now be redirected to the PS Store.  What is extremely odd, I went to the PlayStation Store and did a search for “Development Assistant” and found nothing!  It appears you really do need to click the link above using your browser.  Odd. Click download again:

 

 

2012-04-21-142619

 

 

If everything went correctly, you will now have an icon for PS Suite Dev.  Click it

 

2012-04-21-143546

 

 

 

Now we have to fire up PlayStation Suite Studio, load your project, or a one of the demos ( which are located at “C:\Users\Public\Documents\Pss\sample” on my PC).  Make sure your Vita is connected to your PC via USB cable.  One thing to note here, I had it connected initially to a USB3 port and it didn’t work correctly until I switched to a standard USB2 port.

 

 

Now that Studio is loaded and your Vita is connected with PS Suite Dev is running on it, navigate to Project Menu in Studio and select PlayStation Suite Device Target –> Your Device, like this:

 

 

image

 

 

If your Vita doesn’t show up, try unplugging and plugging back in the USB cable.  Now to actually run your application, if you want to debug simply choose Run->“Start Debugging” or hit F5.  If you want to start without the debugger, choose Run->Run With->Your Vita, like this:

 

 

image

 

 

 

And voila, your application running on your device!

 

 

 

2012-04-21-143608

 

 

At this point, you can ( if you chose Start Debugging or hit F5 ) now debug like normal, set breakpoints, etc… just like running on the simulator.  I have to say, debugging on the device is very smooth; much nicer than many other environments I have worked with.

 

 

I have some code related tutorials coming soon.  Please let me know if there are specific things you are interested in me covering in the future.

General , ,

Month List

Popular Comments

How much interest do you have in Playstation Suite SDK tutorials?
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


19. April 2012

 

 

There is some question if the EULA even allows it, but I am wondering how many of you are interested in Playstation Suite specific content?  I am totally not looking for a reason to justify a Playstation Vita purchase, honest! Winking smile

 

 

Actually, it’s shiny and new and I am easily distracted.  I am quite impressed by what I have seen of the SDK so far, I like working with C# in general so I think I would enjoy writing about Playstation Suite SDK development… if only Sony will actually let me.

 

 

The question is, are the rest of you interested in the subject?

Totally Off Topic

blog comments powered by Disqus

Month List

Popular Comments