While I've rambled on about Screens, Scenes and Cameras I haven't really put up any tutorials in 4 months since "Tutorial 8" and I'm getting a little bit ahead of myself.
So here's a rough TODO list, sort of making this for myself, but it's what I want to cover in detail before I get too off track here:
Screens - a proper introduction to Screens, adding a base Screen class to the Engine
Screen Manager - a simple little tool to help shuffle Screens around
Scenes - like a Screen, but bigger - huge, even. I may rename Scenes to... "Worlds" or "Levels" or, something. Screens and Scenes are conceptually similar with similar names, kind of has an inherent confusion built into it
SceneCameras - this will be the in-depth tutorial on what I've been doing lately. Cameras physically exist on Screens, and are used to peek inside of Scenes
Automation - I have an automation system written, which I can actually take the opportunity to improve upon a little bit as I write it up here on the blog, which allows you to "script" change in game object properties over time. Things like movement, rotation, alpha (fade in/out), changing texture, scaling, stuff like that. This is a very useful for doing UI-ish tasks, like Screen transitions, but I use it for all sorts of other stuff
SceneGraph? QuadTrees? - In a big Scene with lots and lots of game objects, for efficiency sake we will need some way to make quick collision checks between potentially thousands of objects. If a bullet is flying through a level of your game with 5,000 potential objects it could strike, you don't want to check for collision with all 5,000 objects if you can help it. I haven't tackled this yet so it's coming up next on my R&D list
AI - Another R&D project
Level Generation - I've been reading up a little on algorithms for creating random mazes, it's kind of interesting and thankfully not too complicated. I'll use it in the Star Maze project
Sound - I'm assuming this won't be too difficult to implement (famous last words)
Star Maze - take everything covered and use it to re-create a classic 2D game
And beyond that... - like most wanna-be game hobbyists I have an ambitious vaporware project I want to turn into a reality. But first I'll create Star Maze, get some good practice there, and if all goes well we can start to tinker around with other things
xnamachine.blogspot.com should now redirect you to www.xnamachine.com. www.xnamachine.com is now the "official" address.
Nothing else is different, I just decided a more succinct name would be cool.
Well, ok I changed the layout just a little bit... just for fun (I don't know how IE-friendly it is yet). I noticed my formatted code posts don't show up right in IE, so that's kind of a bummer. I'll try to fix that... eventually.
All SceneCameras will by default perform a translation of the subject (e.g., follow it's X/Y position), and all SceneCameras have the ability to scale (zoom in/out). In addition to these two default behaviors there are two optional properties to specify camera style.
Rotate with subject: If this property is True, it causes the SceneCamera to lock rotation with its subject. This creates a camera style whereby the subject appears fixed and the entire Scene rotates. In the video, the SceneCamera on the right side rotates with it's subject. The SceneCamera on the left side has this property set to False, creating an opposite effect (the Scene appears fixed and the subject rotates).
Clamp to Scene: If this property is True, the SceneCamera is not permitted to exit the perimeter of the Scene. In the video, the left side has this property set to True, and it is False on the right side.
Finally, there is a 3rd SceneCamera moving around the perimeter of the Screen to demonstrate the "game object" nature of SceneCameras. Like a Sprite, a SceneCamera can easily be any size, and can move around the Screen without disturbing it's ability to view a subject.
What I will be adding next is a property for Chase lag, so the SceneCamera can be given a variable amount of imprecision when following its subject. Once this is done, the SceneCamera class should be adequately functional.
Here's an example of how you can teach the VBContentManager to load other content types.
This sample code below shows you what to add (in bold) in order to load .fbx models. Please note that to actually display a 3D model, you'll have to write your own 3D rendering code - 3D is out of scope of my 2D engine blog. This just demonstrates how you can teach the VBContentManager to load other content types, the example just happens to use .fbx models.
'Add a Hashtable(Of Model) called Modles, to 'give your models a place to arrive in memory...
Public Models As Hashtable(Of Model)
'Add "intDupeModel" variable to this series... 'This allows the VBContentManager to append a 'unique number to any duplicate filenames it 'may encounter when loading models from disk
'In Public Sub New, add code to instantiate the Models hashtable 'you added above
PublicSubNew(ByVal ServiceProvider As IServiceProvider, ByVal ContentFolder As String)
'(existing code omitted)
'Add code to instantiate the models hashtable
Me.Models = New Hashtable(Of Model)
EndSub
'In LoadAllContent, add a Try block for Model importing in the 'Catch block for Effects, and move the unknown file handler 'to the catch block for attempted Model load
'If that doesn't work, then I've run out of things 'to try, so...
Catch unknown As Exception strUnknownFiles &= vbCrLf & file.FullName EndTry
EndTry
'(existing code omitted)
EndSub
'In HarvestContent, add code to search for .fbx files. Also, 'I'm going to add code to look for .tga texture files as well 'in case I need those too.
PrivateSub HarvestContent()
'(existing code omitted)
'Add code to look for .tga files...
ForEach texture As System.IO.FileInfo In objRoot.GetFiles("*.tga", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) Then Me.intDupeTexture += 1 Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, "") & Me.intDupeTexture.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) EndIf Next
'Add code to look for .fbx files... these are similar 'code blocks, just change the ContentType enumeration and the 'extension we want to look for from all the existing ones in 'this sub
ForEach model As System.IO.FileInfo In objRoot.GetFiles("*.fbx", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Models, model, model.Name.Replace(model.Extension, ""))) Then Me.intDupeModel += 1 Me.objContent.Add(New ContentFile(ContentTypes.Models, model, model.Name.Replace(model.Extension, "") & Me.intDupeModel.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Models, model, model.Name.Replace(model.Extension, ""))) EndIf Next
EndSub
The VBContentManager code should now be able to import .fbx files. Create a folder called Models in your Content folder in the solution explorer, and put .fbx files in there:
Here I copied all the models (and textures) from the SpaceWar example, and they now compile & load into the Models hashtable of the VBContentManager.
I got a chance to get a little more camera work done over the past couple days. What I've made is a 2D camera which is a game object (as such it can be placed onto a Screen just like anything else). These cameras point at "Scenes", which are similar conceptually to Screens, but unlike Screens a Scene is not meant to "draw itself", it just sits in memory. You use a SceneCamera to view a subset of the Scene.
In this demonstration a Scene exists in memory, it's a simple repeating tile grid w/ a user-controlled ship. Multiple SceneCameras are implemented to demonstrate the concept of viewing a Scene through a SceneCamera. All of the SceneCameras are pointing at the same ship in the same Scene.
Pardon the obnoxious music, I was just having fun with Premiere: