Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Flash As2


1 reply to this topic

#1 brentyboy

    Newbie

  • Kontributors
  • Pip
  • 1 posts

Posted 26 May 2010 - 04:07 AM

HI all, im needing help, im in flash as2 and im trying to make my enemys move diagonally downwards and when they reach the limits iv set (the buildings) i want them to bounce off and go the other way, but the way its going one it hits the sides, they just go down straight. i couldnt get it to work with hittests so iv just used > < limits. code as follows:
onClipEvent (enterFrame) {
 enemySpeed = 2;
 sideSpeed = 4;
  
  if (this.hitTest(_root.newBullet)) {
  this.gotoAndStop("dead");
  } 
 this._y += enemySpeed;
 this._x -= sideSpeed;
 
 if (this._x<175) {
  this._x += sideSpeed;
 }
 if (this._x>375) {
  this._x -= sideSpeed;
 }
}

Notice from rvalkass:

Please remember to put code inside Code tags.


#2 Little Asterisk

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 215 posts

Posted 26 May 2010 - 12:41 PM

I don't know how much help you can get with that little information...

So, you want your enemy to bounce off when hitting a wall, right?

What exactly is sideSpeed? The movement of your stage, or something similar?

Basically, if you want your enemy to bounce off in the opposite direction - you need to set its x and y values to increment for minus speed. So, for instance, you would go for this:

this._x += -speed;
this._y += -speed;


As a basic rule of thumb.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users