PDA

View Full Version : [AS2] Problems with movie clip game functions


ScionOfWar
09-02-2008, 05:10 AM
Hello,

I'm new to flash programming and I've just begun my first complicated flash game. Everything's been working pretty well, but I've encountered a couple of problems which I can't find a solution to. I'm going to attach the .fla file so you can look at it and give me your opinion, but here's a description of what I'm struggling with:

First of all, the player symbol has code to shoot cannonballs, which'll hit towers on the map and cause them to stop. However, when I tried to attach code to the towers to give them independent respawning symbols, it also caused them to stop. What I mean by this is, the 'bullets' of the towers -hurt- the towers.

Secondly, I wanted to have the towers not technically shoot bullets, but a unit which'll chase the player around agressively. I was trying to use the code from another program earlier (which caused one symbol to chase the player symbol), and yet it won't trail my player properly. Instead, it goes directly to the place the player was and then stops abruptly. Here's the code attached to the symbol:


onClipEvent (keyDown) {
if (_root.player._x<_x) {
this._x -= 2; }}

onClipEvent (keyDown) {
if (_root.player._x>_x) {
this._x += 2; }}

onClipEvent (keyDown) {
if (_root.player._y>_y) {
this._y += 2; }}

onClipEvent (keyDown) {
if (_root.player._y<_y) {
this._y -= 2; }}



Thank you for the help, here's the link to my media share which contains my incomplete .fla file. Most of the work I've been doing is in layers 2 and 3 of "Scene 2"

http://www.mediafire.com/?xqu42uaif2y

ScionOfWar
09-04-2008, 04:41 PM
Can anyone help me out? Or have any suggestions for an easier method?

dialectric
09-04-2008, 05:21 PM
As for chasing the player, you might look into having the move_towards_player function triggered by a setInterval (or onEnterFrame) rather than a keydown, as it is now, and which may be why the character stops. Look up setInterval on the forums here for how that works.

- dialectric

ScionOfWar
09-05-2008, 12:27 AM
That's a good idea, Dialectric. Originally, it had been 'onEnterFrame', however, I decided I would rather the enemy unit to move only when the player is moving.

The unit *is* supposed to stop, when keyDown isn't initialized, but when it is, the unit is supposed to chase the player. Unfortunately, it only seems to go to the place where the player spawns (and only where the player spawns).

It's as if the _root.player isn't updating as the player moves, or something. >.<

edit: I'll try to move_towards_player function, I accidentally glanced over that when I posted the above thing. Thanks in advance for the assistance!!!