Flash Math Error? Help!
everything going fine until got rediculus values rocket class.
the values meant be:
(importx(initial x value) = 100,importy(initial y value) = 50,xvel = 0,yvel = 0,yacc = 0);
but when debug game , fire rocket get:
rocket y = -107374182.4
rocket x = -107374182.4
yacc = nan
this crazy!!
actionscript code:
package { import flash.display.*; import flash.events.*; public class redrocket extends sprite { private var redexplosion:redexplosion = new redexplosion; private var currentx:int; private var currenty:int; private var importx:int; private var importy:int; private var xvel:number; private var yvel:number; private var yacc:number; public function redrocket(importx:int, importy:int, xvel:number, yvel:number, yacc:number) { trace(yacc); this.x = importx; this.y = importy; currentx= this.x; currenty= this.y; addeventlistener(event.enter_frame, onloop); addeventlistener(mouseevent.mouse_down, destroy); } private function onloop(event:event):void { this.x += xvel; this.y+=yvel; trace("rocket y = " + this.y); trace("rocket x = " + this.x); trace("rocket accel = " + yvel); var radians:number=math.atan2(- yvel,- xvel); this.rotation = (radians/math.pi)*180; yvel+=yacc; } private function destroy(event:mouseevent):void { addchild(redexplosion); trace("boom"); removeeventlistener(mouseevent.mouse_down, destroy); } } };
here's addchild code class gives values:
actionscript code:
redrocket = new redrocket(importx = 100,importy = 50,xvel = 2,yvel = -4,yacc = .1); addchild(redrocket);
nothing crazy - have lot of mistakes in code.
first, instantiate class wrong. pass value pairs while have pass values this:
var redrocket:redrocket = new redrocket(100, 50, 2, -4, .1);
second, don't set values of class' variables in constructor.
More discussions in Adobe Animate CC - General
adobe
Comments
Post a Comment