PDA

View Full Version : MC Targeting



Aur
February 3rd, 2009, 03:47 PM
Ok, so I want to make an rpg style game. The fighting system would need targeting, thus why i'm here.
Basically I want it to work like this: If i click on the enemy, a target arrow or circle pops up around him, but if i click off the target arrow/circle, ect. disappears.
I just want to get this done first i'll start worrying about other stuff soon enough.

Here is what I have, but its not working.

A mc named Ball ( who would be the enemy) with the actionscript
on (press) {
focus == true;
}


a text box to let me know if it is targeted. its a dynamic text box with the var and instance of txtfocus.

and finally on the timeline i have
if (focus = true) {
txtfocus = "sauce";
} else {
focus = false;
}


So far its not working, any tips or help? or even a way to do it better?
thanks--

glosrfc
February 3rd, 2009, 04:02 PM
Firstly, you should use a single equal sign to assign a value to a variable and double equal signs to compare a value. So your code should be focus = true; in the on (press) handler and focus == true in your if condition (or simply use if (focus) instead).

Secondly, to target movieclips effectively you should reconsider placing your code directly onto instances and place it on the main timeline instead, e.g.

Ball.onPress = function() {
focus = true;
}

Thirdly, you could also use the _visible property of your arrow/circle. For example, place an instance of your circle inside the Ball movieclip and then use the following code:

Ball.onLoad = function() {
this.circle._visible = false; // turns the circle off when Ball is instantiated
}
Ball.onPress = function() {
this.circle._visible = true; // turns the circle on
};
Ball.onRelease = function() {
this.circle._visible = false; // turns the circle off
};

JapanMan
February 3rd, 2009, 04:06 PM
Hey,

A mc named Ball ( who would be the enemy) with the actionscript
on (press) {
focus == true;
}
When setting something to true or false, only use one "=." When checking if it is true or false, use two.

a text box to let me know if it is targeted. its a dynamic text box with the var and instance of txtfocus.

and finally on the timeline i have
if (focus = true) {
txtfocus = "sauce";
} else {
focus = false;
}
it should be
if (focus == true) {
textfocus = "sauce";
} else {
focus = false;
}So far its not working, any tips or help? or even a way to do it better?
Hopefully that makes it work. Also, just so you know, there is currently no way of turning off "sauce." All your "else" does is say "if this isn't true, it isn't true," it doesn't actually change it back to false.

Aur
February 3rd, 2009, 05:01 PM
First, i called it "sauce" just because it's a test. And second, I cant get it to work.. :crying:
It makes sense like glosrfc said, if everything was on the timeline. Can someone show me what the code would look like for this in whole? I'll keep working till i get a post.



Oh ya and, as for turing targeting off, i think if I switch it that might work. Like have a mc in the background layer so when that is pressed its targeted instead, or when another enemy.

glosrfc
February 3rd, 2009, 05:39 PM
I used examples for you, e.g. Ball.onPress = function() {
That's pretty much how the syntax goes for targetting movieclips from the main timeline. Give the movieclip an instance name and then use:
instance_name.event_handler = function() {
do something here when the event happens
}

The help files provide more assistance if you search for About dot syntax and target paths.

The event_handlers are similar to the ones you use when you attach the code directly to a symbol except they're written as a single word, e.g. onPress, onRelease, onDragOut, etc. If you check out the AS help files under Movieclip they are all listed in the section headed Event summary.

The main advantages of writing your code this way are:
a) it's easier to use the Target Path Tool in the Actions Panel
b) all of your code is contained in one single place in your FLA.

Finally, I wasn't suggesting that you turn any targetting off...I was suggesting that you turn the _visible property of your arrow/circle on and off. Again, you can find details about this property in the help files under Movieclip or just search them for the term _visible.

Hope that helps

Aur
February 3rd, 2009, 09:13 PM
Ok so i got it working. Changed the code you gave me a little but it works. I have the Scene set up with a background layer named bg, a ball named ball, and a circle inside the ball named circle.(creative, i know :blah:) so heres the code on the timeline
onLoad = function () {
Ball.circle._visible = false;
}
Ball.onPress = function() {
this.circle._visible = true;
}
bg.onPress = function() {
Ball.circle._visible = false;
}