Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile Rules do not take into account other tiles in same tilemap #27

Open
nicbiondi opened this issue May 11, 2018 · 10 comments
Open

Tile Rules do not take into account other tiles in same tilemap #27

nicbiondi opened this issue May 11, 2018 · 10 comments

Comments

@nicbiondi
Copy link

Rule tiles do not take into account positions of other tiles in the same grid even if they are on the same tilemap. It would be nice to have a toggle to allow rules to take other tiles (non rule tile or normal tiles) into account when deciding which sprite to use.

@edwardrowe
Copy link

On our project (Sparklite) we modified the RuleTile to have what we call "sibling" tiles. When deciding if a rule matches, instead of just comparing to 'this' we also see if it's a sibling.

@edwardrowe
Copy link

We also have siblings PER RULE but I'm wondering if that's a hack cause it feels hacky.

@nicbiondi
Copy link
Author

Dang nice work edward!
let's hope this project gets some more love. It really is a beauty. I would also accept giving the Generic Rule tile more than 9 siblings. I know this would be overkill for some uses but for mine it would be nice to be able to set rules for two away rather than just one distance.

@ChuanXin-Unity
Copy link
Collaborator

Checking for other types of tiles or extending the distance of checks is certainly possible, but we wanted to keep the use of the current RuleTile simple.

Lets see if an extended RuleTile would make sense.

@nicbiondi
Copy link
Author

Hi ChuanXin, I agree with this. the default version should be simple to grasp, and it is! This is the first time I have used the RuleTile and ran into the issue of needing to extend the functionality so I thought I would mention it as I believe it will be necessary for many users.

@johnsoncodehk
Copy link
Contributor

johnsoncodehk commented May 16, 2018

I agree that we should keep the current RuleTile simple to use.
I made a version that is extensible and backwards compatible, allowing you to customize fields and rules.

Extension code (Update with 16/6/2018):

public class MyTile : RuleTile<MyTile.Neighbor> {

	public bool customField;

	public class Neighbor : RuleTile.TilingRule.Neighbor {
		public const int Null = 3;
		public const int NotNull = 4;
	}

	public override bool RuleMatch(int neighbor, TileBase tile) {
		switch (neighbor) {
			case Neighbor.Null: return tile == null;
			case Neighbor.NotNull: return tile != null;
		}
		return base.RuleMatch(neighbor, tile);
	}
}

@johnsoncodehk
Copy link
Contributor

I have submitted a pull request for this requirement: #37

@nicbiondi
Copy link
Author

ooh nice! is this pulled? I can't seem to tell. thanks for this!

@johnsoncodehk
Copy link
Contributor

This branch can be found here:
https://github.com/johnsoncodehk/2d-extras/tree/rule-tile-extend

When the author did not confirm the merger of these changes, I suggest not to update it for the time being because everything may change.

@Moonboss
Copy link

** Desperate Noob Here **
I'm a hobbyist, and trying to create random tilemap generation, but don't know where to start. I've tried to absorb as much as I can of the 2D Extras, and Unity videos. I have some questions, and ANY help is welcome!

  1. to johnosoncodehk, or anyone that can answer.. can you decipher the line:
    public class MyTile : RuleTile<MyTile.Neighbor> ?
    I understand basic inheritance, but what I don't understand is the <MyTile.Neighbor> part. Inheriting from something that has a List argument? I'm new to that statement construction.

  2. For learning how to actually produce my own code for Rule Tile scripts, where do I start? i've found a couple videos (specifically Jay Santos' video), and the 2D Extras material, but what else is out there? where should I look for examples/guidance? I've searched and searched and came up with very little.

My End Goal: develop a tile randomization script that will generate custom maps, based on normal tiles and rule tiles. So that in a sense, i'm able to create biomes and coastlines and such that make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants