Need a hint on which class should my class extend

Got a question? Need help? Post here!

Need a hint on which class should my class extend

Postby theLander » Sat Mar 08, 2014 12:31 pm

Hi!
I'm writing a game and one part of the game works with lots of pieces. I've made a Piece class which extends AxSprite. Now I can use properties like Velocity, Drag an so on. But I want to add some text fields on the top of the actual piece graphic so I can track their parameters on the screen in realtime but I can't use Add method to sprite. Can you give me a hint which Ax class shoul the Piece class extend to preserve Velocity and Drag parameters and have Add method as well?
theLander
Private
 
Posts: 5
Joined: Wed Feb 19, 2014 8:54 am

Re: Need a hint on which class should my class extend

Postby Arkeus » Sat Mar 08, 2014 3:16 pm

You *can* do it by making it an AxGroup, and adding the piece and texts to it.

But I'd suggest you separate them out. Have your pieces added to their own group, and the texts added to a separate group. When you create the texts, give them a reference to the piece, and have the text control positioning themselves and whatnot.

Alternatively, you can create the text in the piece, but don't add it to anything. But in the piece's update call the text's update(), and in the draw, call the text's draw().
Image
User avatar
Arkeus
Site Admin
 
Posts: 363
Joined: Mon Mar 26, 2012 12:43 am

Re: Need a hint on which class should my class extend

Postby theLander » Sat Mar 08, 2014 11:33 pm

Thank you! I'm using the code I've pasted below and everything is working just great!

Code: Select all
public class Piece extends AxSprite
   {
      public var pieceText:AxText;

      override public function Piece(x:Number,y:Number,_pieceType:Number)
      {
         super(x, y);
         ...
         pieceText = new AxText(x, y,null,"r,c=",45);
      }

override public function update():void
      {
         super.update();
         pieceText.x = x;
         pieceText.y = y;
         pieceText.update();
      ...
      }

override public function draw():void
      {
         super.draw();
         pieceText.draw();
      }
theLander
Private
 
Posts: 5
Joined: Wed Feb 19, 2014 8:54 am


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron