PDA

View Full Version : wall



kail123
September 4th, 2006, 04:05 PM
I followed this tutorial and tried make walls.When i maked it i haved error
error is:
if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
but i do all good.

DangerousDan
September 4th, 2006, 05:07 PM
What exactly is the error? or does it just not work without giving you a syntax error?

SacrificialLamb
September 4th, 2006, 08:16 PM
what is "this tutorial"? one on this site. can you link to it

JoshuaJonah
September 4th, 2006, 09:51 PM
dan, You can use the ActionScript tags for your footer: [ as ] & [ /as ] without the spaces;)

Joppe
September 5th, 2006, 10:46 AM
Joshua, you can use tags instead of writing [ as ]

Holmesc
September 5th, 2006, 11:52 PM
Hmmm... that tutorial has some weird code. So, I'm going to give you some easier code (I think). So in the main timeline, define variables left, right, and if you're making a top-view game, down and up. So now, make a character, convert him to a symbol, and give him/her ;) the instance name char. Now the coding. To the character give the following actions:

onClipEvent(enterFrame) {
if(Key.isDown(Key.LEFT)) {
this._x += 5
_root.left = true;
_root.right = false;
_root.up = false;
_root.down = false;
} else if(Key.isDown(Key.RIGHT)) {
this._x -= 5
_root.left = false;
_root.right = true;
_root.up = false;
_root.down = false;
} else if(Key.isDown(Key.UP)) {
this._y -= 5
_root.left = false;
_root.right = false;
_root.up = true;
_root.down = false;
} else if(Key.isDown(Key.DOWN)) {
this._y += 5
_root.left = false;
_root.right = false;
_root.up = false;
_root.down = true;
}
} What this code basically does is, whenever a key is pressed (let's say left) all variables but left become false, and the character will be moved by 5 pixels in the correct direction on the coordinate plain. At this point, it won't work because we need to give the following script to the wall/object:

onClipEvent(enterFrame) {
if(_root.char.hitTest(this)) {
if(_root.left == true) {
_root.char._x += 5;
} else if(_root.char.hitTest(this)) {
if(_root.right == true) {
_root.char._x -= 5;
} else if(_root.char.hitTest(this)) {
if(_root.up == true) {
_root.char._y += 5;
} else if(_root.char.hitTest(this)) {
if(_root.down == true) {
_root.char._y -= 5;
}
}
That should pretty much be it! There probably is a better way to do this... but it works for me!

~Holmesc~ 8D