How hard can it possibly be to warp somewhere in sphere?
Depends how hard you want it to be really..
The functions you need to know about are:-
SetPersonX(person, x)
SetPersonY(person, y)
SetPersonLayer(person, layer)
ChangeMap(filename)
The rest presumes you're already in the map engine, moving your input guy around.
So you could make your own warp function like so:-
// start code
// Put this function into your main script file
function Warp(x, y, layer, map) {
if (IsInputAttached()) {
var person = GetInputPerson();
if (typeof(map) == typeof("string")) ChangeMap(map);
if (typeof(layer) == typeof(0) && layer >= 0) SetPersonLayer(person, layer);
if (typeof(x) == typeof(0)) SetPersonX(person, x);
if (typeof(y) == typeof(0)) SetPersonY(person, y);
}
}
// end code
And then you could put:-
Warp(50, 50, 0, "whatever.rmp");
Into a trigger, and you'd go to (50, 50) on "whatever.rmp".
(A trigger is where you right click on the map, and choose Insert Entity > Trigger and type code in the box for when your guy walks over the tile...)
x and y are in pixels.
You don't have to give it a layer or a map.
Let's explain the code:-
function Warp(x, y, layer, map) {
}
This means that we're making our own function, called 'Warp', and it has 4 parameters, called, x, y, layer and map.
Inside the function, we basically have:-
var person = GetInputPerson();
ChangeMap(map);
SetPersonLayer(person, layer);
SetPersonX(person, x);
SetPersonY(person, y);
1) var person = GetInputPerson();
This means make a variable called 'person' and set the value of GetInputPerson() to it.
2) if (typeof(map) == typeof("string")) ChangeMap(map);
This means "if we have a map parameter, we change the map." (note that it makes sure that map is a string)
3) if (typeof(layer) == typeof(0) && layer >= 0) SetPersonLayer(person, layer)
This means "if we have a layer parameter, and 'layer' is equal to or greater than 0, change the layer that 'person' is on to 'layer'"
4) SetPersonX(person, x)
This means set the x value of 'person' to 'x'.
5) SetPersonY(person, y)
Same as 4 but y.
6) What about the lines that started with // ?
Those are just comments.
That seems rather simple, I thought you said it could be more complex?
Sure it can, e.g.
// start code
function WarpObject(x, y, layer, map) {
if (this instanceof WarpObject == false) {
return new WarpObject(x, y, layer, map);
}
this.x = x;
this.y = y;
this.layer = layer;
this.map = map;
}
WarpObject.prototype.warp_to = function() {
if (IsInputAttached()) {
var person = GetInputPerson();
if (typeof(this.map) == typeof("string")) ChangeMap(this.map);
if (typeof(this.layer) == typeof(0) && this.layer >= 0) SetPersonLayer(person, this.layer);
if (typeof(this.x) == typeof(0)) SetPersonX(person, this.x);
if (typeof(this.y) == typeof(0)) SetPersonY(person, this.y);
}
}
// end code
And then you can do:-
var town_door_1 = WarpObject(120, 64, 0, "town.rmp");
var house_1 = WarpObject(60, 60, 0, "house.rmp");
And in one trigger, you can write:-
town_door_1.warp_to();
And in the other trigger you can write:-
house_1.warp_to();
The only real advantage that this has, is it looks pretty and say you have two doors that go to the same place?
You only have to write out the code once, just remember the name you gave the object :)
I want it to fade in and out I hear you cry.
Sure:-
EvaluateSystemScript("screen.js");
FadeOut(1000); // 1000 milliseconds = 1 second.
// Warp() or warp_object.warp_to() here
// draw what you want to fade into, e.g.
// RenderMap();
FadeIn(1000);
Note: Remember the drawing logic rule:- Draw, FlipScreen, Somehow delay so we can see it :)
(Although in this case, FadeIn/FadeOut act as our FlipScreen)
So we get:-
EvaluateSystemScript("screen.js");
function FancyWarp(x, y, layer, map) {
FadeOut(1000); // 1000 milliseconds = 1 second.
Warp(x, y, layer, map);
UpdateMapEngine();
RenderMap();
FadeIn(1000);
}
Okay, I'm done confusing you all.
Enjoy!
Note, that most of the time when you warp to a different map, the layer you want to go to will be the default layer for that map.
If that is so, (due to the way this is written) you can write:
Warp(50, 50, -1, "map.rmp"); // where -1 means default layer
Or:
var mapwarp = new WarpObject(50, 50, -1, "map.rmp")
mapwarp.warp_to();
Please don't write Warp(50, 50, 0, "map.rmp") when you mean the default layer.
Write -1 and that way, if you change the default layer, (say to add reflective ice-tiles) you wont have to change all your warps.
Only write the info that you need for that warp, and you wont have so much to change.
Also, as a final piece of advice.
Instead of putting Warp(50, 50, -1, "woo.rmp") into a trigger, it is better to put: WarpFromFooToWoo();
And in one of your script files, write:
function WarpFromFooToWoo() {
Warp(50, 50, -1, "woo.rmp");
}
That way, if you delete the trigger, you have not lost the warp information, and it's easy to cut and paste WarpFromFooToWoo();
Also, this way, warps don't make you think "where the hell does this go?"
Update:
My current method of warping though is nice and easy.
Create a blank spriteset that is the size of your tiles, set the obstruction base to match the tile sizes.
Call the sprite blank.rss
Now place the sprite on the map,
Name: Door1
Sprite: blank.rss
In the OnTouch Script:
WarpFromNorthDoor("Town1_Inside.rmp", "Door1");
Repeat the process inside Town1_Inside.rmp...
Name: Door1
Sprite: blank.rss
In the OnTouch Script:
WarpFromSouthDoor("Town1_Outside.rmp", "Door1");
Add the code to one of your scripts:
function WarpFromSouthDoor(map, door_name) {
ChangeMap(map);
var x = GetPersonX(door_name);
var y = GetPersonY(door_name) + GetTileHeight() + GetTileHeight();
Warp(x, y, -1, "");
}
function WarpFromNorthDoor(map, door_name) {
ChangeMap(map);
var x = GetPersonX(door_name);
var y = GetPersonY(door_name) - GetTileHeight() - GetTileHeight();
Warp(x, y, -1, "");
}
And then you'll be able to warp to places just by knowing the door's name and the map where it is.
This method is the easiest to maintain. (I think so anyway.)