Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3 Speed pixel-per-second
    primarykey
    data
    text
    <p>A guy on this forum told me to use this: <a href="https://stackoverflow.com/questions/7935114/frame-skipping-on-flash/7935223#7935223">Frame skipping on Flash</a> Instead of doing like <code>thing.x -= 4;</code></p> <p>So I did it:</p> <pre><code>package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.utils.getTimer; public class Seamine extends MovieClip { private var core:Object; private var lastFrame:int = 0; private var thisFrame:int; private var pixelsPerSecond:Number = 100; private var percentToMove:Number; public function Seamine():void{ addEventListener(Event.ADDED_TO_STAGE, onadd); } private function onadd(e:Event){ stage.addChild(this); addEventListener(Event.ENTER_FRAME, loop); } private function loop(e:Event):void{ // Get the miliseconds since the last frame thisFrame = getTimer(); percentToMove = (thisFrame - lastFrame) / 1000; // Save the value for next frame. lastFrame = thisFrame; // Update your system based on time, not frames. this.x -= pixelsPerSecond * percentToMove; if(this.x &lt; 0 - this.width/2) { stage.removeChild(this); removeEventListener(Event.ENTER_FRAME, loop); removeEventListener(Event.ADDED_TO_STAGE, onadd); } if(GlobalVariables.GameOver == 1) { this.alpha -= .03; } if(this.alpha == 0) { this.alpha = 0; stage.removeChild(this); removeEventListener(Event.ENTER_FRAME, loop); removeEventListener(Event.ADDED_TO_STAGE, onadd); } } } } </code></pre> <p>But for some reason, my "Seamine" do take the others x posistion? So it doesn't start at the beginning. Example.</p> <p>1 Seamine start, it have the right speed. Next Seamine spawn but this time, it doesn't start at the "starting x value" because it starts at Seamine 1. </p> <p>I do spawn the Seamines like this: </p> <pre><code>var tm_Seamine:Timer = new Timer (2000); tm_Seamine.addEventListener(TimerEvent.TIMER, Spawn_Seamine); tm_Seamine.start(); function Spawn_Seamine(e:Event){ var SM:Seamine = new Seamine(); var RandomYValue_1_Box:Number = Math.ceil(Math.random()*500); addChild(SM); SM.y = RandomYValue_1_Box; SM.x = 1000; addEventListener(Event.ENTER_FRAME, Hit_SM) function Hit_SM (e:Event){ if(SM.hitTestPoint(Player.x,Player.y, true)) { GlobalVariables.GameOver = 1; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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