Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 7:47 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jan 11, 2010 11:27 pm 
Offline
Site Admin

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 140
I wonder if a copy constructor in Animation is a good addition to the class.
In my case this would be useful because I have a cache of animations and sometimes I reuse the same animation on a number of places, and sometimes I need a new copy.

Code:
  /**
   * Copy images and configuration from another Animation
   * The animation starts at the first frame
   *
   * @param otherAnimation the animation to copy
   */
     public Animation(Animation otherAnimation) {
      this.frames = new ArrayList(otherAnimation.frames);
        this.stopped = otherAnimation.stopped;
        this.stopAt = otherAnimation.stopAt;
        this.autoUpdate = otherAnimation.autoUpdate;
        this.direction = otherAnimation.direction;
        this.pingPong = otherAnimation.pingPong;
        this.loop = otherAnimation.loop;
        this.spriteSheet = spriteSheet;       
        this.currentFrame = 0;
   }


Would this be useful or is there a reason not to add it? as the class seems to be well thought out so there is probably a reason why it is not included.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 12, 2010 4:25 am 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
The use case makes sense to me; but I'm not a big fan of the copy constructor.
I would much prefer to see clone used instead.
Code:
Animation copyAnim = anotherAnim.clone();
have Animation implement the Cloneable interface and perform a shallow clone.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 12, 2010 1:30 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
+1 for clone for me, you can put as RFE here:

http://slick.javaunlimited.net/viewforum.php?f=1

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


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
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group