# Category Archives: DevBlog

## Multiplatform cross-saves

I am very excited to announce that I have implemented multi-platform cross save syncing using your dropbox account. What does this mean for you?  Say you are playing Bik on your phone while on the train.  When you get home, simply sync your saves to dropbox, and then load up Bik on your PC, sync your saves from dropbox and continue playing right where you left off.  All of this happens from a menu within Bik!  This also means you can easily share saves with friends or on the internet. Cross saves currently work between Mac, Windows, Linux, Android, and coming soon to iOS.

## Patching a game

Recently I decided to figure out how I would implement patches for the PC version of Bik.  At first I figured I would just have the player download the entire game again. But because of all the music, the download file will be about 150megs.

## Sorting 2D sprites

As sprites move around the screen in an isometric 2D adventure game, they need to show up in front of and behind other sprites as they move.  Most of the Unity 2d tutorials only address basic sorting and mainly in side-scroller type games.

The way I solve this in Bik is to attach a Baseline.cs script to any sprite that needs to move. If the sprite moves in the XY plane, the script will calculate the Z index depth that the sprite should be at.

Make sure the sprite is aligned bottom so it’s feet are at the transform coordinates of the sprite GameObject.

Here is a simplified version of the script I use in Bik.

```//store the new Z position
float newZPos;
//the camera looking at the sprite
Camera cam;
//the local transform for speed
Transform trans;

void Start()
{
cam = Camera.main;
trans = transform;
}

void Update()
{
//don't run if sprite is not visible to any camera
if(!renderer.isVisible)
return;

//store the viewport position of this GameObject.
Vector3 viewportPos = cam.WorldToViewportPoint(trans.position);

//now we convert our position in the viewport to a usable number for the z order.
//This will always give us a number between 0 and 5. based on the Y value from the viewportPos.
//0 will be the top of the screen and 5 would be the bottom. In the isometric view, objects higher on the screen would be "behind" objects lower on the screen.
newZPos = ConvertScale(viewportPos.y, 0,1,5,0); //See my convert scale method below

//change the Z position of the GameObject to the newly calculated position between 0 - 5.
trans.position = new Vector3(trans.position.x,trans.position.y,newZPos);

}

//this is a static float I use to convert scales.  This is normally placed in a helper script, but i'll show you it here.
public static float ConvertScale (float old_value, float old_min, float old_max, float new_min, float new_max)
{
float new_value = ((old_value - old_min) / (old_max - old_min)) * (new_max - new_min) + new_min;
return new_value;
}
```

Instead of running this in the Update it would be smart to have this script subscribe to a C# event on your Movement script for this character/object. So when the character moves this would be run in a coroutine and then stopped when the character stops moving.
Check out my previous posts for more about Events.

Or just have this as a method directly in your movement script!

Hope this helps someone out! Let me know any questions or comments!

Posted in DevBlog | 5 Comments

## Sequences Revisited

I’d like to show a little more detail on the various types of sequence events.

I’m going to share some xml to demonstrate what happens in a sequence.

Here is a part of a sequence in the game.
First: Tatenen walks to coordinates -3299 x -182
Second: Ammut walks to coordinates -3299 x -244
Third: FadeIn the camera and take 1.5 seconds to do it.
Fourth: Wait 2 seconds while the fade takes place.

``` Tatenen walks left
Ammut Walks left

What is the meaning of this?
```

To run this sequence I have a sequence controller script that will parse this information as coroutines so that we can “yield” to each line.
The NPCWalkToPoint runs code which looks like this (note* this is not the code directly. The real code is much more generic than this. But for demonstration I thought this would be more useful to a beginner to see it fully broken down.):

```float x = float.Parse(node.Attributes["x"].Value);
float z = float.Parse(node.Attributes["z"].Value);
string NPCName = node.Attributes["object"].Value;
//send the npc name and coordinates to a method that makes that npc walk to the coordinates.
yield return StartCoroutine(Movement.NPCWalkToPointNoYield(new Vector2(x,z),NPCName));
```

The next event would be a FadeIn.

```float time =  float.Parse(node.Attributes["FadeIn"].Value;
```

The Wait event

```float time = float.Parse(node.Attributes["wait"].Value);
yield return StartCoroutine(Timer.Wait(time));
```

Make sure the NPC has stopped moving and has reached its destination

```string NPCName = node.Attributes["object"].Value;
yield return StartCoroutine(Movement.WaitForNPCToMove(NPCName));
```

Speak some dialogue!
What is the meaning of this?

```string charName = node.Attributes["spkChar"].Value;
string spkType = node.Attributes["spkType"].Value;
string textToSpeak = node.InnerText;
yield return StartCoroutine(Speach.speak(charName,spkType,textToSpeak);
```

I have probably about 100 or so event types setup in this manner and I constantly am adding more. The idea is to make any events be scripted through the XML and not in code. The sequence controller will parse the xml and run specified methods that do all the work. You could make a very simple visual editor based on this method for scripting events.
Hopefully this gives you some ideas!

Posted in DevBlog | 4 Comments

## Sequence State System

Building a sequence state system is an absolute must for keeping in game sequences manageable.  A sequence is usually a scripted event that the player is not in control of.  It could be a full screen animation or an in game event.   Having this type of system allows you to start or end a sequence at any moment. (more…)

Posted in DevBlog | 8 Comments

## Building an adventure game save system in Unity.

Today I’d like to talk about the save system I designed for Bik.

I’ll try to be as simple as possible so you can use this information in any way you need.  Originally I began to implement my own method and would save the information to XML files but it was taking a while and was not very robust, and I wanted the game to come out before the end of my life, so I turned to the Asset store once again.  I use a plugin called Easy Save 2 for actually writing and reading the variables to and from a file. (more…)

Posted in DevBlog | 5 Comments

## Building a 2D point and click adventure game in Unity3D.

Here is a video demonstration of the latest version of the editor for my framework:

Hi Everyone,
This is the first of many blog posts where I will describe the methods I used to create my Adventure game framework in Unity.

Why Unity?

When I first started working on Bik (in 2012) I was using Adventure Game Studio (AGS).  AGS is dead simple to use and has a really amazing community who actively keep it updated and can help you with just about anything!  After a few weeks into using AGS I realized it had some limitations.  For one, it had no built in  way to handle multiple aspect ratios. This was a big deal because I love widescreen gaming.

Another limitation was its ability to work on multiple platforms.  Yes, there are builds for various platforms including iOS, but these were not working well a year ago and they still are not very easy to get working.  It took Wadjet Eye 8 months to port Gemini Rue to iOS, and I haven’t heard any mention of android from them.

I wanted Bik to work on any device and any resolution.  Since I am one person, I couldn’t afford to spend the time optimizing for each platform. I also thought it would be great to be able to incorporate some form of 3D graphics into the game.  The answer was clear, Unity3D.

Posted in DevBlog | 12 Comments