View unanswered posts | View active topics


Reply to topic  [ 4 posts ] 
Rotating a spaceship bitmap 
Author Message
Member

Joined: Fri May 25, 2012 2:41 am
Posts: 3
Post Rotating a spaceship bitmap
I'm sort of new to AS3. I'm not new to programming in general. This being said, my methods may not be the most efficient, but any help is welcomed.
So.
I'm working on an asteroids game like everybody else. This is the relevant code:
Code:
public class Ship extends Sprite
   {
      [Embed(source = "../../lib/test_ship.png")]
      private var spaceshipClass:Class;
      public var spaceship:Bitmap = new spaceshipClass();
      public var angle:Number;
      
      public function Ship()
      {
         this.angle = 0;
         //rest of constructor
      }
      
      public function move():void
      {
         //adjust angle
         
         //rest of method...
      }
      
   }

I just want to rotate the ship when i press the left and right arrows. I can get the picture to travel in circles with the left and up arrows for example but it doesn't rotate. I left out my failed attempts at rotating so as not to insult your intelligence. I apologize if there's a real simple answer or if I totally screwed something up establishing the picture.


Fri May 25, 2012 3:09 am
Profile
Member

Joined: Mon Sep 20, 2010 8:55 am
Posts: 86
Post Re: Rotating a spaceship bitmap
Try this:
Code:
addChild(spaceship);
spaceship.x = -spaceship.width / 2;
spaceship.y = -spaceship.height / 2;
this.rotation = 45;


Fri May 25, 2012 10:38 am
Profile
Member

Joined: Fri May 25, 2012 2:41 am
Posts: 3
Post Re: Rotating a spaceship bitmap
I put it in the move method and I get
Error: null
Build halted with errors (fcsh).


Fri May 25, 2012 3:31 pm
Profile
Member

Joined: Fri May 25, 2012 2:41 am
Posts: 3
Post Re: Rotating a spaceship bitmap
Ignore that post; I fixed the error. Still not rotating. This is how I applied your suggestion
Code:
public class Ship extends Sprite
   {
      [Embed(source = "../../lib/test_ship.png")]
      private var spaceshipClass:Class;
      public var spaceship:Bitmap = new spaceshipClass();
      public var angle:Number;
      
      public function Ship()
      {
         this.angle = 0;
         addChild(spaceship);
         spaceship.x = -spaceship.width / 2;
         spaceship.y = -spaceship.height / 2;
         this.rotation = 45;
      }
      public function move():void
      {
         //adjust angle         
         this.rotation = angle;
      }
   }

I have it attempting to rotate at different times to see it work but still no rotation. The ship moved from where it usually starts so i can see some of your code working.


Fri May 25, 2012 3:34 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.