Properly Encapsulating A Project

Attached Files

The following files have been attached to this tutorial:

.capx

generic-template.capx

Download now 87 KB

Stats

679 visits, 1,861 views

Translations

This tutorial hasn't been translated.

Tools

Intro

This is my first tutorial, so there might be some screw ups in here regarding hyperlinks, so my apologies. So yea, from what I could tell I didn't see anything talking about Encapsulating a project.

I refer to this tutorial as intermediate, because I think it's something that someone who's generally comfortable with C2 will make better sense of, but there are some important concepts here that a beginner could take from this as well.

This template also includes other things I've found very useful for a typical game including pausing. I made this stripped of all custom plugins so it "should" open for anyone, but I don't know first hand if this capx will open for you without hassle.

Disclaimer: I'm not saying this is the best / only way to do things. There are people out there way more clever at structuring and making things smarter than how I do things. I have so much more to learn about C2.

Background

My very first serious project, I had a lot of things repeating in each event sheet because that's how I knew things would work. Mouse overs.. transitions, etc.

Lots of repeated work. It wasn't so bad when I was just making each scene, but I ran into trouble when I wanted to make some changes to things. What would I have to do if I wanted to change the mouse over or transition speeds? I'd have to go into each event sheet and update that one. It was a drag.

My second serious project though, I'd realized that I could break up things into individual event sheets and attaching those sheets the main event sheets of each scene. This second project was by far easier to manage. So I felt like this might be something that could help others. This community has been incredibly helpful to me so I hope I can continue to offer some tutorials of value in the future.

Ok now for the meat

Here is a link http://part12studios.com/games/Template/ that demonstrates what this capx attached on the left side of the screen contains. However the capx you will get is not going to look exactly the same because I made one for this tutorial that I believe makes no references to plugins I normally use like SpriteFont+ and LiteTween. I stripped them out so I hope the capx opens for you all.

So the basic idea behind encapsulation is that you group certain activities into their own space. In terms C2 this is done by creating a new event sheet. Name it appropriately.. "Monster", "Pause", "Player", "Game Management", etc..

So if we break all this code up all this code, how the heck does anything work? Well the key here is to right click on the event sheet associated with your current scene and "include event sheet". Add any / all event sheets that relate to your current scene... here's an example:

you are at your main menu scene.. called "Main Menu". you have an event sheet also called "Main Menu". You want the main menu to have rain going on in the background, but this rain effect is also see in the "Game" scene. Rather than including the events in both you make a specific Event Sheet and we'll call it "Rain".

You would right click on the "Main Menu" event sheet and add event sheet "Rain" to it. Then when the main menu runs it also includes the code from the Rain event sheet.

It's amazing once you get comfortable with the idea.. you can make your crazy event sheets become so much cleaner breaking up things. If you ever find yourself looking at more than a page of event sheets, consider encapsulation.

I love grouping variables

Another really great thing I've found that's helpful with encapsulation is to make a "Variable" event sheet that is where you put ALL of your global variables so they are all in one place. No more hunting around various event sheets to find the right event.

Deep in a game already with vars all over the place? Notice that C2 actually allows you to move a global variable to another event sheet! So it's very easy to clean things up.

About the template included

Ok so as I said before this template includes more than just a sample of encapsulation, it also covers (at least for me as of right now) the most important things.. though I just realized I left out a version number.. ok corrected... so yea I have it setup like this:

-----

Splash Screen

So the splash screen gives me a space to brand the game but also allows me a place to do some preloading of audio depending on the platform

Main Menu Page

the main menu just gives the game a central location to start and get to places. Level selection and other deeper features would just be new layouts the menu would point too instead of going right into the game.

Credits Page

This is where people can learn more about the game and who's involved. This is a great place to put credits and links to artists and musicians that might be involved especially if they are making their services free in exchange for recognition and sometimes providing links to their sites.

Game

This is a basic game space but notice something? Its empty! Except for a few attached event sheets. have a pause system in place.. So now I can get right into making my game without a bit of prep work done for me and now i can just get into making my game.

I have a basic pause functionality (which you'll need for windows phone 8.0 apps). If you want to do that, you can just wire of the WP8 plugin back button to coincide with the various touch events already defined in here.

I'm not going to explain the pause stuff in this because there are probably other tutorials that show it better. My pause is probably not the best way to do it, but it's the best way I've found that I have figured out.

Hopefully though this template could offer you a way to speed up your game development.. I made this for myself this week after making a few recent games and realizing I'm spending time redoing the same things each time.

-----

That's pretty much it. I'll be happy to explain more / fix anything you see that's wrong. I'll do my best to insure this information is accurate and useful to everyone.

.CAPX

generic-template.capx

Download now 87 KB
  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!