How to put tilemap everywhere?
by Jacob Wagner · in Torque Game Builder · 07/30/2005 (3:12 pm) · 14 replies
I am making a spaceship type game in which the player has full reign to go wherever in the world coordinates he wants to go. The camera is mounted to the player ship.
I have a stars background tilemap, but I need this tilemap to be wherever the player decides to go.
I can't just mount the tilemap to the ship, since I need the player to pass over the stars to show movement.
How do I implement this?
I have a stars background tilemap, but I need this tilemap to be wherever the player decides to go.
I can't just mount the tilemap to the ship, since I need the player to pass over the stars to show movement.
How do I implement this?
#2
I need to show that the player is moving by the player passing over the stars in the background. If I just mounted the tilemap to the ship, you wouldn't know the ship was moving, since none of the stars would move.
Right now I have a big tilemap of stars and it works fine, but once the player flies in any direction too far, the tilemap is left behind.
07/30/2005 (3:46 pm)
Basically what I want is like the game subspace/continuum.I need to show that the player is moving by the player passing over the stars in the background. If I just mounted the tilemap to the ship, you wouldn't know the ship was moving, since none of the stars would move.
Right now I have a big tilemap of stars and it works fine, but once the player flies in any direction too far, the tilemap is left behind.
#3
To make your life easier, you might want to just set up a scroller map and set it's scroll to the vector opposite the player's velocity. I believe that would look something like
07/30/2005 (4:10 pm)
Ah, I gotcha. Just make 4 tilemaps, place them in a 2 x 2 grid, and move them based on where the player is going to be. For instance, if the ship is approaching the edge of the first tilemap on the left side, move one of the three "extra" tilemaps to the left of the original tile map. You need four in case the ship approaches a corner. I hope that makes sense, it's kind of awkward to explain.To make your life easier, you might want to just set up a scroller map and set it's scroll to the vector opposite the player's velocity. I believe that would look something like
$myScrollMap.setScroll(vectorSub2D("0 0", $ship.getLinearVelocity()));
#4
07/30/2005 (4:12 pm)
Thanks. I'll try the scrollermap option :)
#5
~neo
07/30/2005 (4:23 pm)
You could also just switch on wrapping in both X and Y and it will take care of it for you.%layer.setWrap( true, true );
~neo
#6
$starsScrollerMap.setScroll($player1.getLinearVelocityX() * 10 SPC 0);
and that didn't scroll either. Putting in manual values for x or Y DOES work however.
@neo: For some reason, when I use %starsLayer.setWrap(true, true);
, it doesn't work like it's supposed to. I can still fly outside the boundry of the tilemap. I know that I'm using the layer right, since I can set the position of the layer using setPosition and that works fine.
Maybe this is a feature that doesn't work yet?
07/30/2005 (5:24 pm)
@adam: I tried using your setscroll code, but it didn't work. The tiles wouldn't scroll. I then tried a simpler example:$starsScrollerMap.setScroll($player1.getLinearVelocityX() * 10 SPC 0);
and that didn't scroll either. Putting in manual values for x or Y DOES work however.
@neo: For some reason, when I use %starsLayer.setWrap(true, true);
, it doesn't work like it's supposed to. I can still fly outside the boundry of the tilemap. I know that I'm using the layer right, since I can set the position of the layer using setPosition and that works fine.
Maybe this is a feature that doesn't work yet?
#7
07/30/2005 (5:39 pm)
I also tried using setAutoPan and it seems that you can't put a dynamic variable in there either. I guess I'll be implementing the first suggestion. :)
#8
But, I didn't know about the tile layer wrapping. Much better solution. You should mess with that until you get it to work.
07/30/2005 (5:58 pm)
As long as the player's velocity is not "0 0", what I wrote should work. I should have specified, though - you should be calling setScroll() every time the player's velocity changes. i.e, in your keybind functionsBut, I didn't know about the tile layer wrapping. Much better solution. You should mess with that until you get it to work.
#9
Tiles will only be wrapped within the layer itself.
So say you have 10x10 tiles, if you made your layer size
100x100 it would "wrap" those 10x10 tiles into that space.
Try setting your layer size to multiples of the tile area used and
see.
Perhaps I should clarify a bit more:
You have a tile layer:
TileCount(x,y) == (10,10)
TileSize(x,y) == (10,10)
so that would give you 10x10 tiles at 10 units each which means your layer
size should be 100x100.
if however you set the layer size to 200x200 it will then wrap your
100x100 tile layer into that space. Its basically giving it a virtual space
to work in. The rendering code steps through the tiles and if it hits size
it stops. It keeps on rendering tiles until it hits the view clip rect or the
extents of the layer set by setSize().
Note also that I suggested it as just another alternative, Adam's idea is just as
valid and you obviously need to choose which method you use based on your
requirements.
~neo
07/30/2005 (6:18 pm)
I think perhaps you misunderstand how the wrapping works.Tiles will only be wrapped within the layer itself.
So say you have 10x10 tiles, if you made your layer size
100x100 it would "wrap" those 10x10 tiles into that space.
Try setting your layer size to multiples of the tile area used and
see.
Perhaps I should clarify a bit more:
You have a tile layer:
TileCount(x,y) == (10,10)
TileSize(x,y) == (10,10)
so that would give you 10x10 tiles at 10 units each which means your layer
size should be 100x100.
if however you set the layer size to 200x200 it will then wrap your
100x100 tile layer into that space. Its basically giving it a virtual space
to work in. The rendering code steps through the tiles and if it hits size
it stops. It keeps on rendering tiles until it hits the view clip rect or the
extents of the layer set by setSize().
Note also that I suggested it as just another alternative, Adam's idea is just as
valid and you obviously need to choose which method you use based on your
requirements.
~neo
#10
The only difference was, instead of using vectorSub2D("0 0", $ship.getLinearVelocity()) I just used $ship.getLinearVelocity() as the other one was giving me the opposite result of what I wanted. :)
I do have one major problem though: My scroller map has graphical glitches. It shows 1 tile of the picture I used, then between other tiles (which show up fine) there is some weird graphics, it looks like something was stretched out between them. Here's a screenshot of what's happening:

Here is the code I am using for the scrollerMap:
I had no problems making a big tilemap using these graphics btw, i.e. no glitches between tiles.
07/30/2005 (8:22 pm)
I tried adam's method and updated the setScroll on every bindCmd update, that works great. The only difference was, instead of using vectorSub2D("0 0", $ship.getLinearVelocity()) I just used $ship.getLinearVelocity() as the other one was giving me the opposite result of what I wanted. :)
I do have one major problem though: My scroller map has graphical glitches. It shows 1 tile of the picture I used, then between other tiles (which show up fine) there is some weird graphics, it looks like something was stretched out between them. Here's a screenshot of what's happening:
Here is the code I am using for the scrollerMap:
$starsScrollerMap = new fxScroller2D() {scenegraph = t2dSceneGraph; };
$starsScrollerMap.setImageMap(starsImageMap);
$starsScrollerMap.setRepeat("2 2");
$starsScrollerMap.setSize("100 100");
$starsScrollerMap.setPosition("0 0");
$starsScrollerMap.mount($player1,"0 0" ,0 , false, true, true, true);
$starsScrollerMap.setLayer(31);I had no problems making a big tilemap using these graphics btw, i.e. no glitches between tiles.
#11
07/30/2005 (8:28 pm)
I guess I could just go back to a tilemap, and use setAutoPan, but I'm still curious why the scrollermap isn't working.
#12
When I used the tilemap option with setAutoPan, the stars and other objects had a 1 to 1 relationship, i.e. if there was a motionless ship lined up with a star, if i moved somewhere, it would still be lined up with the star.
When I used the scrollermap with setScroll(), the stars did not keep up a 1 to 1 relationship with motionless objects (i can't remember if the stars lagged behind or went faster).
What I want eventually is the stars to lag behind, but I should have no problem doing that now that I've figured this whole thing out using a tilemap and set auto pan and mounting the tilemap to the ship.
07/30/2005 (8:40 pm)
Another oddity: When I used the tilemap option with setAutoPan, the stars and other objects had a 1 to 1 relationship, i.e. if there was a motionless ship lined up with a star, if i moved somewhere, it would still be lined up with the star.
When I used the scrollermap with setScroll(), the stars did not keep up a 1 to 1 relationship with motionless objects (i can't remember if the stars lagged behind or went faster).
What I want eventually is the stars to lag behind, but I should have no problem doing that now that I've figured this whole thing out using a tilemap and set auto pan and mounting the tilemap to the ship.
#13
the camera be mounted on the player ship instead?
~neo
07/30/2005 (9:22 pm)
Perhaps I'm not understanding what your're trying to accomplish but shouldn'tthe camera be mounted on the player ship instead?
~neo
#14
The camera IS mounted to the ship. And I mounted the tilemap to the ship. And I update setAutoPan() whenever the ship changes in movement to pan the tilemap so you can tell the ship is moving because its flying over stars in the tilemap.
All that said though, i'm still confused as to why I got such weird results with scrollermap.
07/30/2005 (11:15 pm)
Well, I've already accomplished what I was set out to accomplish, if you have any questions about that I'll gladly elaborate. :) The camera IS mounted to the ship. And I mounted the tilemap to the ship. And I update setAutoPan() whenever the ship changes in movement to pan the tilemap so you can tell the ship is moving because its flying over stars in the tilemap.
All that said though, i'm still confused as to why I got such weird results with scrollermap.
Torque Owner Adam Larson