Difference between revisions of "RPG LiteNetLib"
(→Getting Squared.Tiled) |
(→Extra Variables) |
||
Line 31: | Line 31: | ||
Squared.Tiled.Object sprite; | Squared.Tiled.Object sprite; | ||
string playerobject, other; | string playerobject, other; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==LoadContent== | ||
+ | Now to load the map, layers and textures. We also assign an instance to sprite, this will be the character controlled by this player. | ||
+ | |||
+ | <syntaxhighlight lang=c#> | ||
+ | map = Map.Load(Path.Combine(Content.RootDirectory, "SimpleRPG.tmx"), Content); | ||
+ | collision = map.Layers["Collision"]; | ||
+ | map.ObjectGroups["objects"].Objects["player1"].Texture = Content.Load<Texture2D>("hero"); | ||
+ | map.ObjectGroups["objects"].Objects["player2"].Texture = Content.Load<Texture2D>("hero"); | ||
+ | sprite = new Squared.Tiled.Object(); | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 12:46, 24 May 2019
Contents
Requirements
You must follow the previous tutorial first: Example LiteNetLib.
From this you will get a working client and server connection, you should be able to start one instance of the game as the client and one instance of the game as the server.
Making it into a game
Getting Squared.Tiled
This example will use a Tiled map for all of the visuals. You will need to create a new class in your project (left click 'Project' and select 'New Class').
Copy the code from this document: Square.Tiled Class
Or from GitHub: GitHub TRCCompSci tiled-xna
Paste it over the whole code pre generated for you new class.
Add Using Refereneces
You will need to add references to the following:
using System.IO;
using Squared.Tiled;
Extra Variables
Add the following extra variables:
Map map;
Layer collision;
Vector2 viewportPosition;
Squared.Tiled.Object sprite;
string playerobject, other;
LoadContent
Now to load the map, layers and textures. We also assign an instance to sprite, this will be the character controlled by this player.
map = Map.Load(Path.Combine(Content.RootDirectory, "SimpleRPG.tmx"), Content);
collision = map.Layers["Collision"];
map.ObjectGroups["objects"].Objects["player1"].Texture = Content.Load<Texture2D>("hero");
map.ObjectGroups["objects"].Objects["player2"].Texture = Content.Load<Texture2D>("hero");
sprite = new Squared.Tiled.Object();