World Units, Position, Scaling - Wierd Occurences
by Michael \"Evic\" Wales · in Torque Game Builder · 04/01/2005 (11:58 am) · 6 replies
A little background on the project - I am trying to make a Pacman clone, because I think it will be easy and I can learn some basics of starting a T2D game from scratch. I have currently made 5 tiles (4 walls, one flat black) and my Pacman avatar. All of my tiles are 32x32, full mode loading for the datablock.
I used the Tile Editor to make my map, which is a simple box using my 4 wall types and the center "playing area" is filled with the flat black tiles.
I am using the default .setCurrentCameraPosition("0 0 100 75")
The following is the code I use to load the tile-map, it's layer, and position it on-screen:
I am simply trying to get the Tile Layer centered on the screen - .setPosition("0 0") works perfectly for this until I add my player's sprite.
I am adding my player's sprite using the following code:
As soon as this is done my tile layer is now in the upper left-hand corner of the view, only being able to see maybe 3-4 columns and 2 rows of tiles (out of 15). My player avatar is loading correctly centered on the screen.
Also, on the topic of world units and what-not, why does setting setLinearVelocityY to a negative number move the player up? Every ounce of intuition in me says Y-Up is positive, Y-Down is negative. The X-axis works as one would think, X-Left is negative, X-Right is positive. What's up with the Y axis? I'm not going to come out and say it's a bug, but there's some logic, theory, trade practice, that I just don't understand...
As for the world units stuff - I really have no idea how to implement my stuff successfully and intelligently. I've read the references, the tutorials, every post in these forums, and it seems like a hit-or-miss job for me. I just keep incrementing/decrementing until I get what I want, and then add something new into the mix, and redo all of my positioning once more.
Can anyone point me into the right direction of making some logic out of this? So I can intelligently setup this example, and my future games, rather than just stumbling on something that works?
Thanks in advance.
I used the Tile Editor to make my map, which is a simple box using my 4 wall types and the center "playing area" is filled with the flat black tiles.
I am using the default .setCurrentCameraPosition("0 0 100 75")
The following is the code I use to load the tile-map, it's layer, and position it on-screen:
function CreateTileMap()
{
// Create tile-map
%tilemap = new fxTileMap2D() { scenegraph = t2dSceneGraph;};
// Load tile-map
%tilemap.loadTileMap("~/client/maps/level.map");
// Get tile layer
%lvlLayer = %tilemap.getTileLayer(0);
// Tile layer setup
%lvlLayer.setPosition("62 62");
%lvlLayer.setTileSize("4 4");
}I am simply trying to get the Tile Layer centered on the screen - .setPosition("0 0") works perfectly for this until I add my player's sprite.
I am adding my player's sprite using the following code:
function CreatePlayer()
{
// Setup player's sprite
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph;};
$player.setPosition("0 0");
$player.setSize("4 4");
$player.setImageMap(playerImage);
// $player.setWorldLimit(clamp, "-56 -56 56 56");
// Player Collision Info
$player.setGroup(1);
$player.setLayer(1);
$player.setCollisionActive(true, true);
$player.setCollisionMaterial(standardMaterial);
$player.setCollisionPolyPrimitive(4);
$player.setCollisionMasks(BIT(2), BIT(2));
$player.setCollisionCallback(false);
// Player's Action Map
new ActionMap(playerMap);
// Bind the Keys
playerMap.bindCmd(keyboard, "up", "playerUp(start);", "playerUp(stop);");
playerMap.bindCmd(keyboard, "down", "playerDown(start);", "playerDown(stop);");
playerMap.bindCmd(keyboard, "left", "playerLeft(start);", "playerLeft(stop);");
playerMap.bindCmd(keyboard, "right", "playerRight(start);", "playerRight(stop);");
}As soon as this is done my tile layer is now in the upper left-hand corner of the view, only being able to see maybe 3-4 columns and 2 rows of tiles (out of 15). My player avatar is loading correctly centered on the screen.
Also, on the topic of world units and what-not, why does setting setLinearVelocityY to a negative number move the player up? Every ounce of intuition in me says Y-Up is positive, Y-Down is negative. The X-axis works as one would think, X-Left is negative, X-Right is positive. What's up with the Y axis? I'm not going to come out and say it's a bug, but there's some logic, theory, trade practice, that I just don't understand...
As for the world units stuff - I really have no idea how to implement my stuff successfully and intelligently. I've read the references, the tutorials, every post in these forums, and it seems like a hit-or-miss job for me. I just keep incrementing/decrementing until I get what I want, and then add something new into the mix, and redo all of my positioning once more.
Can anyone point me into the right direction of making some logic out of this? So I can intelligently setup this example, and my future games, rather than just stumbling on something that works?
Thanks in advance.
About the author
#2
04/01/2005 (12:05 pm)
As you can see 0,0 is at the center... that means up is actually moving negative in the y direction...
#3
As a side note, I was encountering a problem with my player avatar loading up behind my tile layer when I was trying to make some of the tiles collision active. I then had an epiphany and fired up your physics demo. I decided I'm going to just ignore the tile editor method of going about it (the file format will change next launch anyways) and just do it with collision active sprites placed throughout the map to act as the walls.
04/01/2005 (1:42 pm)
Ah thanks for that Matthew, I remember seeing that graph before, I guess I should have paid closer attention to it.As a side note, I was encountering a problem with my player avatar loading up behind my tile layer when I was trying to make some of the tiles collision active. I then had an epiphany and fired up your physics demo. I decided I'm going to just ignore the tile editor method of going about it (the file format will change next launch anyways) and just do it with collision active sprites placed throughout the map to act as the walls.
#4
04/01/2005 (1:45 pm)
I'm not sure on the rendering order so I may be completely 110% wrong on this, but from what i've been seeing on things it seems to render in order of creation. So if you create Sprite A then create Sprite B, and place them in the same spot Sprite B will render on top of Sprite A.
#5
04/01/2005 (1:47 pm)
I tried changing the order of the two being loaded, and was also forcing the player avatar to Layer 1. Still no luck :(
#6
04/01/2005 (1:55 pm)
As I responded on IRC, layer order goes from 31 to 0, with 0 being in front.
Torque 3D Owner Matthew Langley
Torque
will test your problem out later... just a few comments on how things are set up on screen though , hopefully they can help....