Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fryedrycestyle

Pages: [1]
1
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: February 06, 2013, 02:51:54 am »
Excellent, thanks! And yes you're probably right about the caching.

2
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: February 05, 2013, 01:49:49 am »
Sure, I can try to send you something tomorrow.

3
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: February 04, 2013, 03:25:16 am »
Sorry for reviving the thread but I've upgraded to 1.9 and now my camera is acting up again. Essentially the problem from a few posts up (seeing past the edge of the map) has become true again... but only on the X axis.

Code: [Select]
tk2dCamera.inst.mainCamera.transform.position = new Vector3(this.transform.position.x - tk2dCamera.inst.nativeResolutionWidth / 2,
this.transform.position.y - tk2dCamera.inst.nativeResolutionHeight / 2, tk2dCamera.inst.transform.position.z);


if (tk2dCamera.inst.transform.position.x < 0)
tk2dCamera.inst.transform.position = new Vector3(0, tk2dCamera.inst.transform.position.y, tk2dCamera.inst.transform.position.z);
if (tk2dCamera.inst.transform.position.y < 0)
tk2dCamera.inst.transform.position = new Vector3(tk2dCamera.inst.transform.position.x, 0, tk2dCamera.inst.transform.position.z);

if (tk2dCamera.inst.transform.position.x > map.data.tileSize.x * map.width - tk2dCamera.inst.nativeResolutionWidth)
tk2dCamera.inst.transform.position = new Vector3(map.data.tileSize.x * map.width - tk2dCamera.inst.nativeResolutionWidth, tk2dCamera.inst.transform.position.y, tk2dCamera.inst.transform.position.z);

if (tk2dCamera.inst.transform.position.y > map.data.tileSize.y * map.height - tk2dCamera.inst.nativeResolutionHeight)
tk2dCamera.inst.transform.position = new Vector3(tk2dCamera.inst.transform.position.x, map.data.tileSize.y * map.height - tk2dCamera.inst.nativeResolutionHeight, tk2dCamera.inst.transform.position.z);

The code is pretty much the same, just using tile data instead of partition size. Either way it has not made a difference which I use. My tile sheet sprites are set to have a lower left anchor as suggested, but like I said the problem has popped up again, and only on the x-axis.

Any suggestions?

Thanks again.

4
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 22, 2013, 10:59:19 pm »
It was an issue with the tile's anchors. Derp.

Thanks though!

5
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 20, 2013, 10:53:30 pm »
Hey, so I'm still having some minor annoyances with the camera:

If you look at this gallery you'll see what I mean:

http://minus.com/mbrRDDKMQAHr2L

Essentially I have this code to check the bounds of the map (so the camera doesn't pass them):

Code: [Select]
void pCamera()
{

tk2dCamera.inst.mainCamera.transform.position = new Vector3(this.transform.position.x - tk2dCamera.inst.nativeResolutionWidth / 2,
this.transform.position.y - tk2dCamera.inst.nativeResolutionHeight / 2, tk2dCamera.inst.transform.position.z);

if (tk2dCamera.inst.transform.position.x < 0)
tk2dCamera.inst.transform.position = new Vector3(map.width - map.partitionSizeX * map.width, tk2dCamera.inst.transform.position.y, tk2dCamera.inst.transform.position.z);
if (tk2dCamera.inst.transform.position.y < 0)
tk2dCamera.inst.transform.position = new Vector3(tk2dCamera.inst.transform.position.x, map.height - map.partitionSizeY * map.height, tk2dCamera.inst.transform.position.z);

if (tk2dCamera.inst.transform.position.x > map.partitionSizeX * map.width - tk2dCamera.inst.nativeResolutionWidth)
tk2dCamera.inst.transform.position = new Vector3(map.partitionSizeX * map.width - tk2dCamera.inst.nativeResolutionWidth, tk2dCamera.inst.transform.position.y, tk2dCamera.inst.transform.position.z);
if (tk2dCamera.inst.transform.position.y > map.partitionSizeY * map.height - tk2dCamera.inst.nativeResolutionHeight)
tk2dCamera.inst.transform.position = new Vector3(tk2dCamera.inst.transform.position.x, map.partitionSizeY * map.height - tk2dCamera.inst.nativeResolutionHeight, tk2dCamera.inst.transform.position.z);
}

As you can see in the linked image gallery, when I go to the bottom (and also the left hand side of the map), I do not see the complete tiles on the edges of the tile map. However, when I go to right (and also the top of the map) I see past the edge of the tilemap.

Any idea for possible fixes?

Thanks again!

6
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 14, 2013, 02:20:33 am »
Apologies for the double posting, but I have a question regarding tile based movement now.

Code: [Select]
//  UP
if (Input.GetKey(KeyCode.UpArrow))
{
direction = 0;
walk = true;
// this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + 1, this.transform.position.z);
if (map.GetTileAtPosition(currTile, out mapX, out mapY))
{
destTile = new Vector3(currTile.x, map.GetTilePosition(mapX, mapY + 1).y + (map.partitionSizeY / 2), currTile.z);
HOTween.To(this.transform, 1, "position", destTile);
}
}

I'm using HOTween to tween him between two spots but it looks rather "janky" for lack of a better term. The player sprite essentially stutters between tiles. I believe this has to do with the duration of the tween, but when setting it to 0 the player can basically fly across the map in a matter of seconds because they move so fast. I understand this is not 2DToolkit related, but do you have any tips on this front?

Also more related to the plugin, is there an easier way to make sure the player aligns with the tile properly? currTile represents the players world position in a Vector3() (I need to change the name of that variable >.>), destTile is also a Vector3 that represents the world position (also should change the name of that variable).

Thanks again!

7
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 12, 2013, 05:47:20 pm »
I actually just tried the alternative method, of offsetting it by half the resolution in the width and height directions. Seems to work just fine.

Thanks though!

8
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 10, 2013, 03:05:09 am »
Sorry for the staggering amount of questions, but I created an anchor and made the tilemap and the tilemap data children of the anchor. Now the player sprite is in the center of the screen but the anchor doesn't move with the player sprite. I didn't change any code, and when I tried to do it based on the anchor it seemed to cause more harm than good.

So I'm obviously missing something. =S

Any suggestions would be appreciated.

Once again, thanks!

9
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 09, 2013, 09:12:04 pm »
Okay, I'll look into using iTween for Unity or a solution such as that. Thanks for the suggestion.

But now I'm having some trouble with the camera not centering on the screen. I think I'm misunderstanding a few things about how the tk2d camera works?

http://minus.com/lTe7Xskd1oWJ

For the record, I'm spawning my character as a prefab using a tile in the tilemap in case that would make any difference.

The only line of code for the camera:
Code: [Select]
tk2dCamera.inst.mainCamera.transform.position = new Vector3(this.transform.position.x , this.transform.position.y, tk2dCamera.inst.transform.position.z);
Is that. I'm simply trying to have it follow the player, but ideally the player would be in the center of the screen. Am I doing something REALLY stupid here, am I missing something important, or what?

Thanks!

10
Support / Re: Two Questions (Camera / Tilebased Movement)
« on: January 08, 2013, 06:05:36 pm »
Ah okay, so it's just manipulating the mainCamera attribute. That makes sense!

As for my second question, we're making a SNES style RPG, and I figured tile-based movement would be best, as opposed to simply changing the transform's position, basically I want the character to move from one tile to the next in a smooth fashion.

11
Support / Two Questions (Camera / Tilebased Movement)
« on: January 08, 2013, 02:25:18 am »
Hey,

So I'm still getting accustomed to the 2DToolkit and have two questions.

  • How do I manipulate the position of a tk2dCamera? I don't see any explicit way mentioned in the documentation.
  • What is the best practice for implementing tile-based movement for games using the tilemap feature?

Thanks in advance!

12
Support / Re: Moving Animated Sprites
« on: January 08, 2013, 01:10:24 am »
Made lots of sense, in fact I feel bad not having thought of it! Thanks a ton though!

13
Support / Moving Animated Sprites
« on: January 05, 2013, 07:58:02 pm »
Hey guys,

I've just recently purchased the 2D Toolkit, and am pretty impressed so far! However, I'm a bit stuck with something.
My issue is that I have a sprite that I can move around with WASD. When not moving, there is an idle animation. The sprite can move in 8 directions, however there are only animations for the up,down,left,and right. My goal is to have the player face up if W+D or W+A is pressed, and down if S+A or S+D is pressed. However, I'm not quite sure how to do this. In addition, when the player lets go of say the up key and starts walking right or left, I'd like the frame to change to be right or left.

Right now I do my movement in a method called move() which is called by the player's Update() method.

Here is the code, which clearly doesn't work as intended, nor does it even attempt to currently make the player face up/down when moving diagonally.

Code: [Select]
// Player Movement
void move() {

//  UP
if (Input.GetKey(KeyCode.W))
{
direction = 0;
this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + 1, 0);
}

//  LEFT
if (Input.GetKey(KeyCode.A))
{
direction = 1;
this.transform.position = new Vector3(this.transform.position.x - 1, this.transform.position.y, 0);
}

// DOWN
if (Input.GetKey(KeyCode.S))
{
direction = 2;
this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y - 1, 0);
}

//  RIGHT
if (Input.GetKey(KeyCode.D))
{
direction = 3;
this.transform.position = new Vector3(this.transform.position.x + 1, this.transform.position.y, 0);
}

// IDLE

if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.A) ||
Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.D))
{
pSprite.Play("idle");
pSprite.animationCompleteDelegate = null;
walk = false;
}

// WALKING ANIMATIONS

if (Input.GetKeyDown(KeyCode.W))
{
pSprite.Play("walk_up");
pSprite.animationCompleteDelegate = null;
walk = true;
}



if (Input.GetKeyDown(KeyCode.A))
{
pSprite.Play("walk_left");
pSprite.animationCompleteDelegate = null;
walk = true;
}


if (Input.GetKeyDown(KeyCode.S))
{
pSprite.Play("walk_down");
pSprite.animationCompleteDelegate = null;
walk = true;
}


if (Input.GetKeyDown(KeyCode.D))
{
pSprite.Play("walk_right");
pSprite.animationCompleteDelegate = null;
walk = true;
}


}

I also have an attack animation which plays, which is why the direction variable is primarily used (so the delegate knows which direction to resume going to while attacking when moving).

Right now when you press S+D and then release one of the keys to move either down or right, the idle animation plays while moving.

Any help would be appreciated. If anything is unclear, let me know!

Pages: [1]