Hello Guest

Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Ideas / Re: Tiled Support
« Last post by misthema on December 28, 2016, 06:10:12 AM »
http://screencast.com/t/Z285dQwZVXm

 tiled sharp works. Floatvoid has a better understanding of it, however. My line only does a single layer. I have the other one on my machine somewhere that does the layers too.

How do you set your collisions? I only see setting tile IDs for your Tilemap and I'm so lost with collisions...

EDIT: Here's a quick and nasty (but working) solution for Tiled maps (uses TiledSharp):
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using Otter;
using TiledSharp;

public class TiledMap : Entity
{
class _Tileset
{
public string Name;
public TmxTileset TmxTileset;
public ImageSet TilesetImage;
}

readonly string pathMap = string.Empty;

public TmxMap TmxMap;
public int FullWidth, FullHeight;

GridCollider _gc;
List<_Tileset> _tilesets;

public TiledMap(string path) : base()
{
pathMap = path;
_tilesets = new List<_Tileset>();
Load();
}

public void SetCollisionLayer(string layer, Enum tag, params Enum[] tags)
{
_gc = new GridCollider(FullWidth, FullHeight, TmxMap.TileWidth, TmxMap.TileHeight, tag, tags);
setupGridCollider(layer);
AddCollider(_gc);
}

public void SetCollisionLayer(string layer, params int[] tags)
{
_gc = new GridCollider(FullWidth, FullHeight, TmxMap.TileWidth, TmxMap.TileHeight, tags);
setupGridCollider(layer);
AddCollider(_gc);
}

void setupGridCollider(string layerName)
{
var layer = TmxMap.Layers.FirstOrDefault( x => x.Name.Equals(layerName) );

for( int y = 0; y < TmxMap.Height; y++ )
{
for( int x = 0; x < TmxMap.Width; x++ )
{
int tileID = y * TmxMap.Width + x;
_gc.SetTile(x, y, layer.Tiles[tileID].Gid > 0);
}
}
}

public void Load()
{
TmxMap = new TmxMap(pathMap);

if( TmxMap.Orientation != OrientationType.Orthogonal )
throw new FormatException("Tilemap Orientation invalid! Only [Orthogonal] supported.");

FullWidth = TmxMap.Width * TmxMap.TileWidth;
FullHeight = TmxMap.Height * TmxMap.TileHeight;

// Load tileset images
foreach( var tileset in TmxMap.Tilesets )
{
var imgSet = new ImageSet(
tileset.Image.Source,
tileset.TileWidth,
tileset.TileHeight
);

_tilesets.Add(
new _Tileset{
Name = tileset.Name,
TmxTileset = tileset,
TilesetImage = imgSet
}
);
}
}

public override void Render()
{
foreach( var tmxLayer in TmxMap.Layers )
{
// Render visible layers only!
if( !tmxLayer.Visible )
continue;

// Layer tiles
var tiles = tmxLayer.Tiles;

for( int y = 0; y < TmxMap.Height; y++ )
{
for( int x = 0; x < TmxMap.Width; x++ )
{
var i = y * TmxMap.Width + x;
var tileID = tiles[i].Gid;
var tileset = tilesetForGid(tileID); // get right tileset for this tile!

if( tileset == null )
continue;

var firstGid = tileset.TmxTileset.FirstGid;
var frame = tileID - firstGid;

tileset.TilesetImage.Frame = frame;

var tx = x * TmxMap.TileWidth;
var ty = y * TmxMap.TileHeight;

tileset.TilesetImage.Render(tx, ty);
}
}
}

_gc.Render();
}

_Tileset tilesetForGid(int gid)
{
foreach( var tileset in _tilesets )
{
var first = tileset.TmxTileset.FirstGid;
var last = first + tileset.TmxTileset.TileCount;

if( gid >= first && gid < last )
return tileset;
}

return null;
}
}


USAGE:
Code: [Select]
public class TestScene : Scene
{
public TestScene()
{
var tm = new TiledMap("path/to/your/map.tmx");
tm.SetCollisionLayer("Name of your Collision layer", YourCollisionTagEnumerator.Value);
Add(tm);

this.UseCameraBounds = true;
this.CameraBounds = new Rectangle(0,0, tm.FullWidth, tm.FullHeight);
}
}

Supports multi-tilesets too, but lacks all the other cool stuff you could have. It's very minimalistic.

...But it works:

22
Help / Re: Multipass shaders in Otter2d
« Last post by Kyle on November 02, 2016, 03:33:47 PM »
Hey!  I have time for a quick answer at the moment:  Surfaces actually have the "AddShader" method which allows them to automagically take care of each pass.  You can see how this is done around Surface.cs Line 561, and implement this yourself if you want, or if you're using a Surface already you should be able to just keep adding shaders to it and have it use all of them in the order they're added.
23
Help / Multipass shaders in Otter2d
« Last post by KrissLaCross on November 01, 2016, 03:15:13 PM »
Hi!

So I'm trying to implement a basic multipass shader using this tutorial: https://gamedevelopment.tutsplus.com/tutorials/how-to-write-a-smoke-shader--cms-25587
But I'm struggling with seting up the multipass system aka "The Frame Buffer Trick".
The simpel algorithm goes as follow:
  • Pass A through your shader, render onto B.
  • Render B to the screen.
  • Pass B through shader, render onto A.
  • Render A to your screen.
  • Repeat 1.

Where A and B are either two textures or two buffers. I decided too use two Surfaces, because that makes it easier to create some cool stuf later on.
But I'm struggling with step one, I'm just not really sure how too do this in Otter2d. I tried the following:
Code: [Select]
bufferA.Shader = shader;
bufferB.Draw(bufferA);
bufferB.Render();
tempBuffer = bufferA;
bufferA = bufferB;
bufferB = tempBuffer;

using the this simpel shader:
Code: [Select]
uniform sampler2D texture;

void main() {
vec4 color = texture2D(texture, gl_TexCoord[0].xy);
color.r += 0.01;
gl_FragColor = color;
}

But sadly it doesn't work and I don't know what I'm doing wrong.

I appreciate any help!
Thanks for your time!

~KrissLaCross
24
Help / Re: Tile Pixel Manipulation
« Last post by Lycake on October 22, 2016, 09:37:40 AM »
Thanks for the quick reply!

Hm is it possible to only color the grayscale part of the sprite? Coloring the whole tile wouldn't work because I have fixed colored parts that shouldn't be tinted and stay as they are.

Oh and yes I have requested a slack invite but havn't gotten any email yet (yes I checked the spam folder)
25
Help / Re: Tile Pixel Manipulation
« Last post by Commanderstitch on October 22, 2016, 09:23:52 AM »
I usually just white/greyscale my sprites/tiles and set them to whatever color i want at runtime. That's just what i do atm. I've never tried this pixel manipulation of individual pixels since c++. Good luck with your stuff! I'll see if i can't get others to read this on the forum and check it out. Most of us are in the otterslack. join up and have a chat. we'd love to see you.
:-)
26
Help / Tile Pixel Manipulation
« Last post by Lycake on October 22, 2016, 08:38:22 AM »
Hello!

I am using a tilemap similar to the principle of the game Dwarf Fortress. It works like this: You have transparency, gray pixels, and colored pixels on the tiles. Together with the tile number, you get a foreground and a background color. The the transparency defines the amount of background color on that pixel, the gray pixels the amount of foreground color and the colored pixels are unchanged.

This makes it so you can use the same tiles for different objects in your game - colored differently. For example you can have a bucket out of copper or iron (using a reddish or gray foreground color), while having pre-colored blue water with one single bucket tile.

Now my problem is, that I need to change the gray pixels in my tiles to the foreground color (or rather merge it, because I need various degrees of foreground color brightness, depending on the darkness of the gray pixel). I can't seem to find an approach that works. I couldn't find a way to change my tiles on a pixel per pixel basis manually and my other thought was using a shader, but shaders only work on the whole tilemap and not on individual tiles. Coloring the whole tile also changes the true colors in the tiles, which should stay unchanged.

I know this forum isn't very active anymore, but I really hope someone has an idea how to solve my problem. I really like otter so far and hope I can use it with this project of mine.

Thank you,
Lycake
27
Ideas / Re: Embedding in WinForms
« Last post by Kyle on October 12, 2016, 07:56:46 PM »
Hmm I can't make any promises on this front. This seems to require a core modification of the game loop. If I can figure out a good way to implement this in the current API without changing a bunch of stuff, then I can check this out.  My current priorities at this point are to fix a few more bugs in the engine, and convert it over to the FNA runtime sometime next year.

This definitely would be possible though on your own branch if you want to fork it and modify the loop in Game.cs to work with a windows form.
28
General / Re: Atlas and Animation
« Last post by plague_boy on October 12, 2016, 01:19:28 AM »
Heh, no worries Kyle.

I'm just happy to be having fun again. Otter has got me out of a loooong creative funk.

N
29
General / Re: Atlas and Animation
« Last post by Kyle on October 11, 2016, 08:02:05 PM »
Unfortunately right now there's no such support -- the only support for TexturePacker atlases is using an atlased image as the source for a spritemap.  I'm not sure if I'm able to add support for this in the near future, sorry :I
30
General / Atlas and Animation
« Last post by plague_boy on October 11, 2016, 08:22:26 AM »
Hi folks, I'm an Otter newbie and this may be a really dumb question but is there any way to use sprite names  - generated from TexturePacker to create sprite animations?

example:

sprite.add(Animation.idle, "player_idle1, player_idle2, player_idle3", 3);

Cheers,

Nick
Pages: 1 2 [3] 4 5 ... 10