Be a Supporter!

AttachMovie Positioning issue...

  • 242 Views
  • 10 Replies
New Topic Respond to this Topic
AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
AttachMovie Positioning issue... 2011-01-03 13:06:45 Reply

First off, I have to say that I use AS2. Go ahead, yell at me for not using AS3, it won't change a thing, because what I use doesn't support it.

Here's the thing.

I have a MovieClip on the main timeline (CharacterSprite).
Within said CharacterSprite are multiple MovieClips on different frames, which are his actions/movements that I go to whenever he does something.

Now, I want him to throw something, so when pressing a key, I go to a certain frame within CharacterSprite, which holds the MovieClip of the animation where the CharacterSprite throws said thing.

Then, at the end of that animation, because the thrown object is drawn along with the sprite for the animation to look how I want it to, I have an attach movie code which attaches a movieclip of the thrown item onto that CharacterSprite and then moves forward.

The thing is, to spawn the object where I want it to (for it to work with the animation), I pretty much have to make it spawn on CharacterSprite coords + whatever, depending on where the item is supposed to appear when he lets go of it, or rather, when the animation itself ends.

It attaches fine, but because it is "thing._x = CharacterSprite._x", when the CharacterSprite moves after throwing it, the Movieclip of the item moving forwards follows those Coords.

Basically, what I need is a way to attach or load the MovieClip at the CharacterSprite Coords + whatever and then, once it is, make it so that it doesn't follow the CharacterSprite anymore, but still go through its normal animation of moving forward.

Or, in a more simpler way; I need to "anchor" my Projectile's Movieclip to the CharacterSprite Coords as it is attached, and have it not move anymore. Is there such a way?

Also note that I'm no expert at ActionScripting, so I may need intensive details on how to do that, if it is even possible.

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 15:02:51 Reply

I would use a different method for determining the position of the projectile. Right now you have the projectile always using the co-ordinates of the character to determine it's position.

What you should do is have the projectile separate from the character completely and only make the projectile's starting position the same as the character when you hit the "throw" button.

So in bullet form what you'd want to do is:

-User hits throw button (or however you're telling the character to throw)
-projectile starting co-ordinates = character co-ordinates at moment of button push
-projectile starting co-ordinates +=speed of projectile (assuming you want it to go in a straight line)


BBS Signature
AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 16:20:35 Reply

Yea, but how do I make it so that the projectile starts at the same coordinates as the character as the "throw button" is pressed, but doesn't THEN follow the character?

I'm thinking I might need some sort of listener to constantly check the character's coordinates, but I haven't the slightest clue how they work. ^^;

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 16:37:47 Reply

You have 2 variables for XOrigin and YOrigin that you make equal to the character's x and y position at the moment of the button push and you do that in the function that occurs when the button is being pushed so that they don't change unless you push the button again.

Then you make the projectile's x and y co-ordinates equal to the XOrigin and YOrigin + the speed of the projectile


BBS Signature
AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 17:42:23 Reply

I don't exactly understand how that works, or at least, how to code it for it to work because if I do make variables = charactersprite's X and Y, at least the way I know how to make it, it'll just be the same thing, only, with an extra variable in-between CharacterSprite's X and Y coords and the projectile...

like, say...

XOrigin = _root.CharacterSprite._x
YOrigin = _root.CharacterSprite._y

just as the animation for the throw is started (since if you move before the animation is complete, you cancel the throw), and then, as the movieclip is attached, its coords are equal to XOrigin and YOrigin.

But since those two are already = to the CharacterSprite's coords, and will keep being equal, they're really just redundant variables

How do I make them check for that "Origin" coord and retain it, instead of updating themselves everytime CharacterSprite moves?

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 18:02:04 Reply

Like I said previously:

You only make XOrigin and YOrigin equal to the character origin when the throw button is pushed. So say you have a function that controls what happens when the throw button is pushed: (keep in mind this is pseudocode and is closer to AS3 syntax anyway so don't just copy and paste)

var speed = 10;

function throw(){ //this happens when you push the throw button
     XOrigin = characterX;
     YOrigin = characterY;
}

function projectileMove(){
     projectileX += XOrigin;
     projectileY += YOrigin;
     for(i=0; i<50;i++){
          projectileX +=  speed;
     }
}

so! if the character is at x = 300 y = 500 and the throw function is called then the XOrigin and YOrigin would become 300 and 500 respectively.

Then in the projectileMove function the projectileX becomes 300 and the projectileY becomes 500 then in the for loop projectileX becomes 310 then in the next loop it becomes 320 etc for 50 times

so with that it is not using the character's coordinates for anything except to determine where to start the projectile.


BBS Signature
AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 18:37:21 Reply

Well, see, the way I've got it set up is this...

CharacterSprite moves around on root, which is the world in which the game takes place.

CharacterSprite is a movie clip.

Within, are several movie clips on a single frame each, with stop(); put on, so that if CharacterSprite takes an action, pressing the keyboard's keys associated with said action will make CharacterSprite go to that action's frame.

Now, within those frames, as I said, is a movie clip. In this case, it's a movie clip of the CharacterSprite throwing a projectile.

That, as I said, is a movieclip and, on the last frame of that movieclip, when CharacterSprite is about to let go of the projectile, I attach a movieclip to CharacterSprite. Movie Clip of the projectile moving forwards.

I'm not actually using a function to make it move, I've already preset its path and speed through a movieclip, which I'm attaching to CharacterSprite.

So yea, basically, "ThrownProjectile_mc" is attached to CharacterSprite and has its coords, but as I stated being my problem, it keeps following the CharacterSprite as he moves, so it doesn't work.

As for your example function, well, while I understand it, it wouldn't work, because it would move the movieclip itself forward, or in this case, to the right, which I don't want to do since my projectile is already moving within the movieclip.

See my problem?

Or are you saying I shouldn't make it move within my movieclip and use that function to do so? That might work...

I shall try, but, just for the hell of it; thoughts?

AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 19:22:42 Reply

Well, I tried everything I knew.

Nothing seems to work, even if I try your code (although modified for it to work with my stuff)

I'm really just getting annoyed at this thing. Seriously, I know that ActionScript is complicated and is way too vague to be able to tell you excatly what you need to do so you can do all that you want, but goddammit, stuff like "Syntax Error" is pissing me off.

It's like, Okay, so something's wrong here... WHAT!? TELL ME THE EFF WHAT!!?!?!?

Ah well, I'm done ranting.

If anyone has any other ideas for a newbie at AS, you're welcome.

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 19:38:19 Reply

Oh! I didn't realize that the projectile was inside the character movie clip. Of course it's going to move with the character :P as far as actionscript is concerned they're the same movie clip. What you need to do is make a separate movie clip of the projectile outside of the character movie clip


BBS Signature
AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-03 19:47:06 Reply

well it is outside, that is what I'm attaching to CharacterSprite.

I tried just attaching it to _root, but no matter what coords I add, it always stays stuck on 0,0

So, I dunno what I'm doing wrong.

I mean, if I attach it to _root.CharacterSprite, then it follows him when it actually gets attached, but if I attach it to _root alone, nothing. Any idea on that?

Ah and, I enter the attach code on the last frame of the "ThrowProjectile_mc" which, itself, is within "CharacterSprite_mc".

Pressing a key activates a line of code within Charactersprite_mc which tells it to gotoandstop on the fram that "ThrowProjectile_mc" is on.

Doing so, it plays "ThrowProjectile_mc" and on its last frame, it attaches the projectile itself to be thrown.

That's where I'm having trouble because, as I said, it keeps following "CharacterSprite_mc" due to "= Charactersprite X and Y", and, if I attach it to Root, well, I'm just going around in circles now aren't I? XD

So yes, any idea how I can fix this?

AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AttachMovie Positioning issue... 2011-01-04 14:39:06 Reply

So, trying things out, I notice that if I attach the projectile's mc to charactersprite, not only does it move with it, but it also increases charactersprite's size and thus, causes problems to all of my hittest borders and such, so that's a no go.

So obviously, what I need to do, is attach it to root, however, I just can't seem to give it any coords other than "0, 0" because it always stays stuck in the upper left corner, no matter what I try.

I just tried this one...

_root.attachMovie("ProjectileDown", "Projectile"+ProjectilesThrown , this.getNextHighestDepth [this._x = 100, this._y = 200]);

but to no avail. I have tried, earlier, to make this._x = CharaterSprite._x, same for y, but again, doesn't work, it stays in the top left corner. What am I doing wrong here? Isn't that last bpart, after depth, supposed to be for coords?
If so, why is it not working?
if not, why did I think it was that, what is it, and how do I give coords to the attached movie then?