FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Arc: The Road to version 0.10
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic     Forum Index -> ArcLib
View previous topic :: View next topic  
Author Message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Sat Apr 22, 2006 2:34 pm    Post subject: Reply with quote

Ok, I'm going to try and figure out things your way.

I havn't given a reply because dsource has been down, so bear with me as I edit this post to give a full reply. I'm not as stubborn as I may seem, I just need to fully understand a design that's agreed upon before I can implement it. Smile Of course I'm not going to implement a design that you'll never use.

[edit1]

First off, your right. Sprite should be simple enough so it doesn't look awkward using it for just 1 frame, and complex enough to support multiple animations and sounds. This is easy to conceptualize, but difficult figure out a good design for.

Based on what you said, here is an initial design that I came up with. If I missed something from what you said or you think you have a better design, please show me by modifying the code below + give reasoning.

Code:


// how it would look using sprite for a single frame ///////////////
Sprite s = new Sprite("frame.png", COLLISION_TYPE.COL);
s.draw();

// multiple animations //////////////////////////////////////////
Sprite s = new Sprite(COLLISION_TYPE.COL);
s.addFrame("frame.png", "animation1");
s.addFrame("frame2.png","animation1");

s.addFrame("frame3.png", "animation2");
s.addFrame("frame4.png","animation2");

// set current animation
s.setAnim("animation1");

// set the time between frames in milliseconds
s.setAnimSpeed(100);

// if you want the frame to speed up or slow down during animation. gradient will be used as a multiplier. Here every other frame will be twice as fast as the previous one.
s.setAnimSpeedGrad(2);

s.draw();

// attaching sounds to animations ///////////////////////////////
sprite.addSound("water.wav", "animation1");



this good?
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun Apr 23, 2006 9:57 am    Post subject: Reply with quote

Quote:
I havn't given a reply because dsource has been down, so bear with me as I edit this post to give a full reply. I'm not as stubborn as I may seem


You haven't seemed much stubborn at all Smile

Quote:
This is easy to conceptualize, but difficult figure out a good design for.


I did already have this implemented in what I called OPAL for C++, and my design was much as I just posted.

Quote:
this good?


It is good, but there are a few issues with it... These things are not really 'bad' things, however:

* all animation frames will have the same length
* what frame does the sound play on? Does it play just when the animation starts or every loop of the frames?
* how do you know if the animation loops or not...?
* you can't index a frame in an animation (e.g. you couldn't do that 'artist custom rotation' frame indexing i posted earlier) -- unless you had a string "static_anim_45_degrees" for every frame of rotation?

And are strings going to be slow at indexing animations...? I know D has some cool char[] indexing stuff... haven't really used it much myself.

Let me send you my OPAL code and you can look through how I did my OPAL_SPRITE, because it had animation, sounds for each animation and everything... it is done in C++, and used OpenLayer and Allegro, but the data structures were rather simple and easy to read...


Last edited by Phr00t on Sun Apr 23, 2006 10:16 am; edited 2 times in total
Back to top
View user's profile Send private message
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun Apr 23, 2006 10:03 am    Post subject: Reply with quote

OK, look at these include files:

They are slightly old, but you should see how the interface works, hopefully you can get some insight from it.

http://www-unix.oit.umass.edu/~jvight/mirror/stuff/opal.h

OPAL_GRAPHIC is an array of BITMAPS and SAMPLES (pictures and sounds) with no X, Y kinda stuff. I used this to draw tiles in OPAL_TILEMAP as well. I guess this is like a 'dependent' frame after all Wink OPAL_GRAPHIC has things like how long the frame exists, what the next frame is etc.

OPAL_SPRITE is the main beef. It contains an OPAL_GRAPHIC, and handles drawing, collision detection etc. The collision detection is a bit outdated / nonworking Smile

OPAL_GROUP was a pretty neat concept... you could save off all the current sprites into a 'group', and then load in another group of sprites -- I used this for things like switching rooms / levels etc.

There is probably a better way of doing this, and your system would work too. See what you can come up with, but its good that all ARC fans-to-be will have a good class to work with Smile

OPAL_TILEMAP worked pretty good too, drawing tiles that just show on the screen, could be scrolled around, animation / sounds in tiles.. click on tiles etc.
Back to top
View user's profile Send private message
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun Apr 23, 2006 2:30 pm    Post subject: Reply with quote

Quote:
Or are you saying the length between frames will be static? Yes, but you can also have it speed up or slow down with gradient, what more do you need?


Hrm... If you always wanted frame 5 to be on longer than frame 4, you would have to check which frame was playing, and then call the speedGradient function to slow the next frame, and then after the frame ends, call speedGradient function again to speed it back up...

This isn't much of a problem unless you want different frames playing at different speeds within an animation :-\

Quote:
However, if you do need more, then I can simply add an option to give a time display amount for each frame, would this fix it?


Yeah, I guess it would Smile

Quote:
I figured it would play at the first frame.


Hrm.. I used sounds in animations to give a 'step' sound for every 'step' of the player animation, so my animation had two frames in it with sounds that would play everytime that frame was started.

Quote:
I figured it would keep looping until you either call a
sprite.stop() function or switch animations.


OK.. fair enough. But that requires you to monitor the animation to see when you want it stopped? Like when an end-of-animation frame is reached?

Quote:
I don't think I fully understood your solution to it. I'll look it over again.


If you had 8 frames, 1 for each 45 degree turn of a 'creature'. You could set the frame in relation to the current angle of the creature's sprite:

creature.setFrame( cast(int)(creature.angle / 45) );

so if the creature was at angle 45, it would set the frame to frame 1 -- which would make the creature look like it is facing northwest etc.

Quote:
Yea, a string can index it. I thought it made the code more readable and newbie friendly


OK, cool.

Quote:
Ok, I'll look over it and try to come up with a design similar, but make it as readable as possible so for someone who's never seen the code before (me) can make sense of it the first time they read it.


You don't have to come up with something similar... just use it for whatever you want. It contains implementation of the ideas I am talking about. Yes yes, readable is good -- my code might not be very readable Smile

[ edit ] Weird! now my post replaced yours! Some odd bug, huh?
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Sun Apr 23, 2006 6:23 pm    Post subject: Reply with quote

Your opal.h code confuses me, I think I'll start with a simple design and evolve it as necessary. Here's my second attempt at a design, note how I'm bent on using string index's.

First, each frame will need to
#1) Which animation it is apart of
#2) What image it will be composed of
#3) Whether it will play a sound once it reaches there, + all sound info
#4) How long it will be displayed

The animation can be a char[]. The image can be a char[]. The sound can be a SoundFX class that will hold all sound info, or null if no sound needed. The length of display will be a time amount in milliseconds.

Code:


Sprite s = new Sprite(COLLISION_TYPE.NULL);

s.addFrame("animation1", "ball.png", new SoundFX or null, 30);
s.addFrame("animation1", "ball.png", new SoundFX or null, 30);
s.addFrame("animation1", "ball.png", new SoundFX or null, 30);
s.setAnimLoop("animation1", true);


I would also operator overload as necessary to give the user whatever amount of control he desires for the frame, and use default values otherwise. Also, I'll probably re-arrange the order to reflext the percentage of use.

The code will create a 3 frame animation that will loop. If you don't want a loop, then choose 'false'.

Does this design have all the required flexibility?
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun Apr 23, 2006 7:17 pm    Post subject: Reply with quote

Quote:
Does this design have all the required flexibility?


I think so Smile

I'd assume there would be default values for the SoundFX = NULL, frame_time = 30 (or so) and frame_bool = false ?

Hrm, so if you set a frame's 'loop bool' to true in the middle of the animation, it would make any future frames useless because they would never be reached? I guess this isn't an issue if they just handle that boolean correctly...

Quote:
note how I'm bent on using string index's.


They are nice to work with, until you want to do math with them :-\
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Sun Apr 23, 2006 7:33 pm    Post subject: Reply with quote

Quote:

I'd assume there would be default values for the SoundFX = NULL, frame_time = 30 (or so) and frame_bool = false ?


Yes.

Quote:

Hrm, so if you set a frame's 'loop bool' to true in the middle of the animation, it would make any future frames useless because they would never be reached? I guess this isn't an issue if they just handle that boolean correctly...


Edited my post to fix this.

Quote:

They are nice to work with, until you want to do math with them :-\


True, easy to read but bad at math. How about converting numbers to strings?

int numAnim = 0;

char[] anim = "anim" ~ toString(numAnim);
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun Apr 23, 2006 8:40 pm    Post subject: Reply with quote

Quote:
How about converting numbers to strings?


Yes yes you can do that...

How are you going to be able to probe which current frame is being displayed? Like if you wanted a bullet to only shoot on the third frame (that is the frame the muzzle flashes) -- how would you do this?

char[] getCurrentFrame()? which would return the current animation string plus some integer? Then you have to do string comparisons to check whether it is actually the third frame?

Just had a good idea (and compromise):
"int getCurrentFrame(char[] animation)" which returns the index of frame being played in animation (-1 if 'animation' is not the active animation), and then have a "bool setCurrentFrame(char[] animation, int frame_index)" -- returns true if the frame exists and is set. This might work even better, because it allows the string to be the "main" category of the animation, but the single frames can still be individually selected / polled if needed.

If you had this, then you can also support frames with "millisecond lengths" of -1 (static frame), so if a frame is reached with a length of -1, it stops there. Then a programmer can later set a different frame.

What do you think?
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Sun Apr 23, 2006 10:07 pm    Post subject: Reply with quote

This post will contain the final implementation for the first version of the sprite class. Here's what i have so far...

Code:

class Sprite : Entity
{
// constructors

// perpixel frame construct
...this(char[] frame, COLLISION_TYPE, float gap);
...this(COLLISION_TYPE, float gap);

// single frame const
...this(char[] frame, COLLISION_TYPE type);
// generic contstruct
...this(COLLISION_TYPE type);

// draw and do calculations
...process(); // calculations
...draw();     // draw to screen
...drawBounds(); // draw bounds, box, circle, nothing if pixel

//set-get properties
...set/getPosition();
...set/getColor();
...set/getAngle();
...set/getWidth/Height();
...set/getZoom();

// special
...set/getRadius();

// add frames
...addFrame(char[] img, char[] anim="default", int time=30, SoundFX sfx=null);
...addFrame(char[] img, char[] anim, int time);
...addFrame(char[] img, char[] anim);
...addFrame(char[] img);

// get/set frame functions
...char[] get/setCurrAnim();
...int get/setCurrFrameNum();
...Frame get/setCurrFrame();

...int getCurrentFrame(char[] animation);
...bool setCurrentFrame(char[] animation, int index);

// loop or not
...bool setAnimLoop(char[] anim, bool v);

...bool collision(Sprite s);

private:

COLLISION_TYPE col;

Animation[char[]] animations;
char[] currAnim;
int currFrame;
x,y;
r,g,b,a;
float angle;

// special rotational values
float pivX, float pivY;
float nx, float ny;
}


Last edited by clayasaurus on Mon Apr 24, 2006 5:40 pm; edited 6 times in total
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Mon Apr 24, 2006 1:50 pm    Post subject: Reply with quote

Looks good! Smile

Process() I assume will handle just animation/sounds?

Oh, can you change the zoom (or width, height) of a Sprite?

e.g. sprite.setWidth(...) ?

And, will this effect collision detection?

- jeremy
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Apr 24, 2006 3:08 pm    Post subject: Reply with quote

Phr00t wrote:
Looks good! Smile

Process() I assume will handle just animation/sounds?

Oh, can you change the zoom (or width, height) of a Sprite?

e.g. sprite.setWidth(...) ?

And, will this effect collision detection?

- jeremy


Added... process() is just my way of separating drawing code from stuff like timing code, sound code, calculations that need to be done, etc.

For changing the sprite size, here it what can be done...

boxframe... nothing special needs to be done except change vars

radframe... recalculate radius based on size of frame, note that user can
still override the size of radius

pixframe... will have to recalculate each frame with a different size. not recommended to call each frame.

which reminds me of a radius function i need to add..

also i'm in finals this week and next week which means i just work on this in small spare pieces of freetime.
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Mon Apr 24, 2006 4:04 pm    Post subject: Reply with quote

Quote:
also i'm in finals this week and next week which means i just work on this in small spare pieces of freetime.


OK, sounds good.

My finals don't start until May 19th Razz
Back to top
View user's profile Send private message
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Wed Apr 26, 2006 8:58 am    Post subject: Reply with quote

After updating ARC's SVN, I noticed it didn't compile Sad

So I checked in some updates to ARC. It now compiles, and runs with no errors. I had to make the mouse image a Sprite, I had to private import opengl.gl in some file, and I made Sprite() actually initialize a frame in the animation in the constructor. I also added support for times of -1 to not go to the next frame. However, I cannot get sprites to display on the screen. I believe a new frame is being created under the name "default", but after setting the position and calling draw(), nothing appears on the screen. Sad

Maybe you can look into this when you have the chance?

- jeremy
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Wed Apr 26, 2006 8:42 pm    Post subject: Reply with quote

You just made 1 checkin, right? I'm going to revert to my previous version and continue working on Sprite class from there.

For future reference: unless you are adding a totally new feature, you are kind of stepping on my toes by working on the exact same thing I am. Once I get a testing branch up you can help me fix bugs in there, or you can help add a totally new feature, but I was kind of working on the Sprite class which is why it didn't work, I wasn't done with it, so I'll revert back and just continue from what I had previously done.

If you just want something to work with until then, then I think v349 will work for you. Also, if you read the commit logs, you'd see my message 'sprite most likely doesn't work.'

Or, maybe it is just best if I keep sole SVN control and have people submit patches instead.

edit: i fixed sprite to be able to draw the frame, but now SVN is down. arg.
edit2: svn back up, i guess apache just restarted itself. changes are in. it is still not fully complete.
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Thu Apr 27, 2006 9:20 am    Post subject: Reply with quote

I fixed the sprites to draw on my copy too, and I was about to check it in Smile

I realized the drawing problem was width/height variables not being set correctly (they were NaNs) -- also PivX and PivY were getting NaNs. I assume you made the same fixes as I was (e.g. initializing the PivX =0, PivY = 0, and initializing the width/height of the sprite to the first frame added)

Also, I was performing a .rehash after every addition of a new animation (you have to check whether a new animation exists in anim by doing (animation in anim) kinda thing...

Quote:
you are kind of stepping on my toes by working on the exact same thing I am


You can look at it that way, or look at it as "Oh, he fixed some bugs and some things work now... I'll spend 5-10 minutes to see how he fixed things, and go from there"

[ edit ] OK, just checked out your version and it works, good job.

[ edit2 ] You should add a rehash in after a new Animation object is added to anim with the associative array -- and have a check whether time > -1 (or similar) to go to the next frame (e.g. support times of less than 0 to mean 'never automatically go to next frame')
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> ArcLib All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 3 of 7

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group