Sprite.rotation does not work if it is not initialized with a value different than 0

Bug #959336 reported by Sebastiano
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
jeash
Fix Committed
Undecided
Niel Drummond

Bug Description

create a test using this code:

package ;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Shape;

class SpaceShip extends Sprite
{
 var _bmp:Bitmap;
 var _mouseDown:Bool;

 public function new()
 {
  super ();

  var bitmapData = nme.Assets.getBitmapData ("assets/images/bship.png");

  _bmp = new Bitmap(bitmapData);

  this.addChild(_bmp);

  this.addEventListener(Event.ENTER_FRAME, onRender);
  this.addEventListener(Event.ADDED_TO_STAGE, onStage);

  _mouseDown = false;
 }

 private function onMouseDown(evt:MouseEvent):Void
 {
  _mouseDown = true;
 }

 private function onStage(evt:Event):Void
 {
  stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);

  this.removeEventListener(Event.ADDED_TO_STAGE, onStage);//otherwise it is called twice

  var rect:Rectangle = _bmp.getBounds(this.parent);

  _bmp.x -= ((rect.width / 2));
  _bmp.y -= ((rect.height / 2));

  x = (stage.stageWidth / 2);
  y = (stage.stageHeight / 2);
 }

 private function onRender(evt:Event):Void
 {
  this.rotation = CalcRotation();
 }

 private function CalcRotation():Float
 {
  if (_mouseDown == false) return this.rotation;

  return 57;
 }
}

Once the mouse is clicked, instead to see a sudden change of rotation like expected, the sprite will be also translated to the corner of the screen (right down in my case);
IF the sprite rotation is initialize to 1 inside the OnStage function, then everything works as expected.

Revision history for this message
Niel Drummond (niel-drummond) wrote :

Because it's not a pure haxe/jeash project and uses NME, I cannot compile this as it is posted.

Is it possible that you zip your project, with Assets, with NMML file, and Source directories so I can compile it without deviating from the code you have provided ?

Revision history for this message
Niel Drummond (niel-drummond) wrote :

I guess the stage should be rotated properly around the center of the screen, or is the stage not supposed to fire any mouse events at all ?

Changed in jeash:
assignee: nobody → Niel Drummond (niel-cyanescent)
status: New → Confirmed
Revision history for this message
Niel Drummond (niel-drummond) wrote :

Thanks for the bug report(s).

Changed in jeash:
status: Confirmed → Fix Committed
milestone: none → 0.8.8
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.