Jump to content


Photo

Tile Swap


  • Please log in to reply
13 replies to this topic

#1 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 29 June 2012 - 02:28 PM

Tile Swap
Author: Tsukihime

tileSwap1.jpg

Overview

This script allows you to easily change tiles on the map.

Download

Script: Get it at Hime Works
Tutorial: Easy Tile Swapping. I would recommend reading this to see how this script works.

Examples:

Making a bridge
A crack in the wall

Credits

KilloZapit, for providing the code for auto-tile generation.

Usage

There are three types of tile swaps

1. Change by tile id
-All tiles on the map with the specified ID will be changed to a new tile
 
tile_swap(old_tileID, new_tileID, layer, map_id)

2. Change by region id
-All tiles that are covered by the specified region ID will be changed to a new tile
 
region_swap(regionID, tileID, layer, map_id)

3. Change by position
-The tile at the specified position will be changed to a new tile
 
pos_swap(x, y, tileID, layer, map_id)]

You can undo changes by using the following calls 
 
tile_revert(tid, layer, map_id)
pos_revert(x, y, tid, layer, map_id)
region_revert(rid, layer, map_id)
revert_all

For performance reasons, you should avoid swapping tiles by ID. It goes through every tile on the map to see if it needs to be changed, and if you have a large map, it will take some time to perform. This is meant for large-scale tile swaps where it is unfeasible to specify using regions or positions.

It is recommended that you stick with region tile swapping and position tile swapping.

Understanding tiles

This script uses the concept of a "tile ID", which is a special string
that represents a particular tile on your tileset.

The format of this tile ID is a letter, followed by a number.
The letters available are based on the tileset names

A, B, C, D, E

The number represents the ID of the tile.
So for example, "A3" would be the the third tile in tileset A, whereas
"B12" would be the 12th tile of tileset B.

An example usage would be
 
tile_swap("A9", "A1", 0)

Which will swap all "A9" tiles on layer 0 with "A1" tiles. As usual, because I did not pass in a map ID, it is assumed to be the current map. Please check the new script call format for details.

It is very easy to look up the appropriate ID: just look at your tileset and number the top-left tile as 1. Then, numbering left-to-right, top-to-bottom, you would get something like this

tileSwapGuide.jpg

For tileset A, it is a little different. This is assuming you have all 5 parts in tileset A.
You will need to skip over any missing pieces appropriately if you do not have all 5 parts.

To avoid all this unnecessary math, simply fill up the empty slots with dummy tilesets to make things easier.

Edited by Tsukihime, 25 February 2013 - 02:35 PM.

himeworks011.png
My scripts.

Avatar by ShinGamix

#2 Monthigos

Monthigos

    Tata

  • Member+
  • 48 posts
  • LocationSomewhere
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 23 July 2012 - 10:32 PM

This is a great script! So far I've used it to make an extending bridge.

Posted Image


#3 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 16 February 2013 - 08:13 PM

Script updated.
Some bugs fixed.
Auto-tile updating has been implemented. Thanks to KilloZapit for the auto-tile generation code.

Now the tiles look proper after swapping

tileSwap1.jpg

Usage same as before.
I have added support for using letters instead of just numbers for the tileset.
For example:
pos_swap(10, 15, 8, 0, "A")
pos_swap(10, 15, 8, 0, 1)

This changes layer 0 of the tile at position (10, 15) to tile 8 of tileset A.
Both statements do the same thing, except maybe the letter makes it easier to remember what's going on.

If you have any suggestions for improving the script calls I will consider them. Right now it seems too verbose and unintuitive.

Edited by Tsukihime, 16 February 2013 - 08:21 PM.

himeworks011.png
My scripts.

Avatar by ShinGamix

#4 dragonborn99

dragonborn99

    Advanced Member

  • Members
  • 173 posts
  • Primarily UsesN/A
  • First LanguageAustralian

Posted 16 February 2013 - 08:44 PM

This pretty cool and handy... I am going to save this script and use it for sure This is awesome!!!

Please join my website and the official forums!
Every one that joins gets a discount in my first game: SWORD OF VENGEANCE!

http://ironwinggames.webs.com/apps/forums/


#5 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 17 February 2013 - 02:58 AM

I have revised the entire script.
Please be aware of the following changes.
The changes were made in order to increase user-friendliness of the script.

1. The input tile ID is now a string composed of two pieces of information: the tileset as a letter, and the ID as a number.

"A7" would be the 7th tile in tileset A
"B2" would be the 2nd tile in tileset B
"C4" would be the 4th tile in tileset C

An example usage would be
tile_swap("A9", "A1", 0)

Which will swap all "A9" tiles on layer 0 with "A1" tiles. As usual, because I did not pass in a map ID, it is assumed to be the current map. Please check the new script call format for details.

2. It is very easy to look up the appropriate ID: just look at your tileset and number the top-left tile as 1. Then, numbering left-to-right, top-to-bottom, you would get something like this

tileSwapGuide.jpg

For tileset A, it is a little different. This is assuming you have all 5 parts in tileset A.
You will need to skip over any missing pieces appropriately if you do not have all 5 parts.

A1 starts at 0 and goes to 15
A2 starts at 16 and goes to 47
A3 starts at 48 and goes to 79
A4 starts at 80 and goes to 119
A5 starts at 120 and goes down to the last number

To avoid all this unnecessary math, simply fill up the empty slots with dummy tilesets to make things easier.

Edited by Tsukihime, 17 February 2013 - 03:25 AM.

himeworks011.png
My scripts.

Avatar by ShinGamix

#6 ShinGamix

ShinGamix

    DS Style 4Ever!

  • Members
  • 1,097 posts
  • LocationAlien Ship
  • Primarily UsesRMVX Ace
  • First LanguageApril Fools

Posted 17 February 2013 - 03:01 PM

I wish there was a demo for this.
-How to make a bridge
-How to water flow out.
-Hole in walls
-Secrets like Zelda:aLttP

retrog10.png

 

That's my spoiler don't open it till xmas

Spoiler

 


#7 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 17 February 2013 - 04:17 PM

Bridge making: http://forums.rpgmak...ing/#entry99030
Hole in wall: http://forums.rpgmak...ing/#entry99046

For flowing water, you would use position swapping in your event with wait events in between.

Don't know about zelda secrets.
himeworks011.png
My scripts.

Avatar by ShinGamix

#8 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 4,313 posts
  • LocationAustralia
  • Primarily UsesN/A

Posted 17 February 2013 - 04:26 PM

I LOVE this script!

It looks like the changes are not retained when you leave the map, and are lost on exiting the game. I suppose both could be managed with a parallel process event controlled by a switch to do all the setup on loading, which is fine.

I'm not sure I understand about the flowing water (and I assume waterfalls, or in general, anything on the A1 tile). Perhaps you could make an example for that one as well?

What are your terms for commercial use?

#9 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 17 February 2013 - 04:38 PM

The changes should be preserved since the script is designed so that you have your original map, and then you have your custom tile data stored in $game_system. Whenever the map loads, it will see if there are any custom tiles to draw and then go ahead and draw them, so the custom stuff is stored in the savefile and handled automatically.

I have added the terms to the script. Free for commercial use.

There may be some script compatibility issues at the moment which may have resulted in the new tiles not being preserved.
I have updated the script just now to address some compatibility issues.

By flowing water, I'm assuming it's like you start with an empty canal, and then water pours in and starts filling it up from say left to right. Given that each tile is 32x32 I don't think it would be possible to make it look like water is gradually filling up the canal without some extra stuff...

Edited by Tsukihime, 17 February 2013 - 04:45 PM.

himeworks011.png
My scripts.

Avatar by ShinGamix

#10 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 4,313 posts
  • LocationAustralia
  • Primarily UsesN/A

Posted 17 February 2013 - 04:56 PM

Ah, I looked through the script, but missed any reference to $game_system.

My reference to flowing water is in response to this:

For flowing water, you would use position swapping in your event with wait events in between.


Oh - I just realized that's probably exactly what you're talking about. You could probably also do it with regions. Initially I thought you meant changing a non-water area into a water area that requires animation, but it just clicked that that's exactly what you did in your tutorial.

#11 ShinGamix

ShinGamix

    DS Style 4Ever!

  • Members
  • 1,097 posts
  • LocationAlien Ship
  • Primarily UsesRMVX Ace
  • First LanguageApril Fools

Posted 17 February 2013 - 05:56 PM

I guess i meant "water draining".

 

As for Zelda secrets would be like a bomb blast opening a wall

or picking up a stone and a staircase appearing under it

or pushing

 

but I guess these would be done more with events.


retrog10.png

 

That's my spoiler don't open it till xmas

Spoiler

 


#12 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 25 February 2013 - 01:29 PM

Here is something I am considering: Area swap.
When you're mapping, it is common to select tiles like this

tileSwapArea1.jpg

Rather than just selecting a 32x32 tile, you select a group of them and then place them on your map.
This is useful for objects that are larger than 32x32, such as bridges or that stone thing.

The currently planned script call looks like
area_swap(x, y, tileID, width, height, layer, mapID)

Where

(x,y) is the position where the rectangle will be drawn
tileID is the tile ID of the tile in the top-left corner of your rectangle
width is how many tiles across will be taken (1 to 8, default 1)
height is how many tiles down will be taken (1 to 32, default 1)
layer is the layer you want to draw it on, default 0
mapID is the map this applies to, default the current map ID

If anyone has any further suggestions or things I should taken into consideration now is a good time before I actually implement it.

I have only considered area position-swapping, but area region-swapping doesn't seem too bad either.
I don't know what to call it though. region_area_swap?

Edited by Tsukihime, 25 February 2013 - 03:31 PM.

himeworks011.png
My scripts.

Avatar by ShinGamix

#13 GnlMarcus

GnlMarcus

    Newbie

  • Members
  • 7 posts
  • Primarily UsesRMVX Ace
  • First LanguageFrench

Posted 25 February 2013 - 03:41 PM

I don't know if this would fit, but i'm trying to swap region id's on specific tiles.

let's say in a conditional branch

 

if switch 2 is on

then region_swap (1)

else region_swap (0)

end

 

i'm not great at scripting at I thought this could maybe fit in.



#14 Tsukihime

Tsukihime

    Advanced Member

  • Members
  • 2,568 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 25 February 2013 - 03:46 PM

region_swap does not mean swapping regions. It means "swapping tiles by region ID".
Unless you were talking about your own region swapping idea.

I have thought about providing a way to swap region ID's, but I would leave that for a different script.

Edited by Tsukihime, 25 February 2013 - 03:47 PM.

himeworks011.png
My scripts.

Avatar by ShinGamix




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users