Copy link to clipboard
Copied
Okay i am creating a tile based game, everytime i move the character i want to store his walking direction for example dirx = 1 , diry = 0. The idea being that when my enemies reach a tile where the character has been it can load the directions and walk the same way. How do i associate the directions with the current tile?
Something like this is my idea but i dont know how to actually program it.
private var giveTileDirections():void
{
var xdir = this.dirx;
var ydir = this.diry;
}
Thanks in advance
How you write the code depends on what class the code is associated with. "this" will be identifying the class object, which based on your description will be a tile, so if you want to assign the direction of some other object (the character) then you want to target that character, not "this"
When you declare the function, you use the word "function", not "var"
When you declare the variables you should designate what class they are, and they should be declared outside the function if you intend t
...Copy link to clipboard
Copied
How you write the code depends on what class the code is associated with. "this" will be identifying the class object, which based on your description will be a tile, so if you want to assign the direction of some other object (the character) then you want to target that character, not "this"
When you declare the function, you use the word "function", not "var"
When you declare the variables you should designate what class they are, and they should be declared outside the function if you intend that they be available outside of the class.
So the code might look something like this but only you can figure out how you actually want to program it and what you actually intended for each thing you showed....
public var xdir:int;
public var ydir:int;
private function giveTileDirections():void
{
xdir = character.dirx;
ydir = character.diry;
}
Copy link to clipboard
Copied
Wow i was really tired when i wrote this discussion. Thanks for your help i figured it out. How do i remove a discussion like this one?
Copy link to clipboard
Copied
The only way you can remove a discussion is to do so before someone answers it. It won't hurt to keep it in the event someone else learns something from it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now