Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are only making it bounce back when X is less than 0... So what is happening is that the object hits the wall (x is less than 0) moves back to just past 0 (actually to 0 because you have if it is less than 0) and then starts to go back toward the wall again until it is less than 0 (almost instantly). So you will see the object just stuck at the wall (x=0).</p> <p>One way that I tend to approach this is store a different direction variable that is either +1 or -1. Once the object passes 0 (x&lt;0) i set the direction to +1. Once the object hits however far I want to go to the right I set the direction back to -1. Then every time I am increasing the x position by the movement speed I multiply by direction which will only change the direciton not the speed.</p> <pre><code>private function Update(evt:Event) { for (var i:int = 0; i &lt; moneyVector.length; i++) { // Figure out what direction to move if ( moneyVector[i].x &lt; 0 ) { direction = 1; } else if(moneyVector[i].x &gt; maxX) { direction = -1; } // Multiply by direction to move the correct way moneyVector[i].x += moneyVector[i].dx * direction; moneyVector[i].y += moneyVector[i].dy; if (moneyVector[i].hitTestObject(character)) { Config.CurrentStage.removeChild(moneyVector[i]); moneyVector.splice(i, 1); moneyscore += 400; moneytext.text = "Money : " + moneyscore.toString(); money = new Money ; money.dx = RandomRange(-5,5); money.dy = RandomRange(-5,5); money.x = X[chooseSpawnPoint()]; money.y = moneysourceY; Config.CurrentStage.addChild(money); moneyVector.push(money); } } } </code></pre> <p>Don't forget to store direction as a varible for each moneyVector index and set whatever you want your maxX to be instead of where I have "maxX"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload