Collisions draw correctly centered on sprite (ish)
authorunknown <ivan@.ne.tamu.edu>
Thu, 20 Jan 2011 16:59:49 +0000 (10:59 -0600)
committerunknown <ivan@.ne.tamu.edu>
Thu, 20 Jan 2011 16:59:49 +0000 (10:59 -0600)
Animation.cpp
ArtAssets/Sprites/sun.anim
ArtAssets/Sprites/viking.anim
Frame.h
Sprite.cpp

index fca422c..85d590c 100644 (file)
@@ -69,6 +69,7 @@ int Animation::loadAnimation(std::string animFile)
                                double x=0.0, y=0.0;
                                value>>x;
                                value>>y;
+
                                
                                /** Collision data */
                                char c;
@@ -116,17 +117,16 @@ int Animation::loadAnimation(std::string animFile)
                                
                                /** sets frame delay and makes sure height and width are correct */
                                mAnim[count].pause = pause;
-                       if(!mW) mW = mAnim[count].image->w; 
-                       if(!mH) mH = mAnim[count].image->h;
+                               mW = mAnim[count].image->w; 
+                       mH = mAnim[count].image->h;
                                
                                /** Set the animation Peg*/
-                               mAnim[count].animationPeg = Point2D(x,y);
+                               mAnim[count].animationPeg = Point2D(x + double(mW)/2, y + double(mH)/2);
 
                                count++;
                        }
        }
        }
-       /// \todo add collision info obtained from file.
   fin.close();
   return 0;
 }
index 29e9d82..b466db1 100644 (file)
@@ -2,7 +2,7 @@
 #ArtAssets/ milisec    Transparency
 #filename      pause   r       g       b       xOffset yOffset ( collisionType <Circle has offset, radius | rectangle has offset, width, height>, ... )
 NumFrames: 4
-sun1.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 )
-sun2.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 )
-sun3.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 )
-sun4.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 )
+sun1.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
+sun2.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
+sun3.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
+sun4.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
index 02056f4..56ad9a8 100644 (file)
@@ -2,12 +2,12 @@
 #ArtAssets/ milisec    Transparency
 #filename      pause   r       g       b       xOffset yOffset ( <n | c | r> <Circle has offset, radius | rectangle has offset, width, height>, ... )
 NumFrames: 9
-viking1.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking2.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking3.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking4.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 r -6.0 3.0 5.0 5.0 )
-viking5.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking6.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking7.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking8.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
-viking9.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 )
+viking1.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking2.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking3.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking4.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0  c 0.0.0 5.0 )
+viking5.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking6.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking7.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking8.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
+viking9.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 )
diff --git a/Frame.h b/Frame.h
index 5a574c3..e2628da 100644 (file)
--- a/Frame.h
+++ b/Frame.h
@@ -9,8 +9,8 @@
 struct SpriteFrame{
        SDL_Surface *image;/**< Pointer to an image. */
        int pause;/**< Tells the amount of time to pause between this frame and the next. */
-       int width;/**< Base width of the frame's image. */
-       int height;/**< Base height of the frame's image. */
+       int width;/**< Base width of the frame's image. \todo make this and animation's match or at least sync or delete*/
+       int height;/**< Base height of the frame's image. \todo make this and animation's match or at least sync or delete*/
        vector<Point2D> hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/
        Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */
        vector<Collision*> collisionData;/**< The collision data for this sprite */
index 98b528a..1899da9 100644 (file)
@@ -44,5 +44,5 @@ void Sprite::draw()
        if(mVisible == true)
                SDL_BlitSurface(frame.image,NULL,mScreen,&dest);
        if(Game::game()->ShowCollisions)
-               drawCollisions(frame.collisionData, frame.animationPeg);
+               drawCollisions(frame.collisionData, mPos + frame.animationPeg);
 }