public bool PerformAnimatedSpriteFrame(AnimatedSprite sprite, BCBlockGameState gamestate) { //task: increment rotation and frame number. CurrentRotation += RotationSpeed; bool returnresult = !gamestate.GameArea.Contains(new Point((int)Location.X, (int)Location.Y)); //Location= new PointF(Location.X+Velocity.X,Location.Y+Velocity.Y); Location = VelocityChange.PerformFrame(gamestate,Location); return returnresult; }
public void Draw(AnimatedSprite sprite, Graphics g) { //Draw: takes into account the rotation and the current frame. //First, get the Image we need to draw: Image drawthis = CurrentFrameImage; if (drawthis == null) return; PointF centerpoint = CenterPoint(); //now,proceed to change the transform matrix of the graphics object... //Debug.Print(CurrentRotation.ToString()); //rotate around the center of the object. //create a new Matrix, also, a temporary one to cache the graphics objects original matrix. Matrix cached = g.Transform; rotationmatrix.Reset(); //rotationmatrix.RotateAt((float)CurrentRotation, centerpoint); rotationmatrix.RotateAt((float)CurrentRotation, centerpoint); //draw it... g.Transform = rotationmatrix; //g.DrawImage(drawthis, Location.X, Location.Y, Size.Width, Size.Height, useImageattributes); g.DrawImage(drawthis, new Rectangle((int)Location.X, (int)Location.Y, (int)Size.Width, (int)Size.Height), 0, 0, drawthis.Width, drawthis.Height, GraphicsUnit.Pixel, useImageattributes); //now "revert" the transform... //g.Flush(); g.Transform = cached; //g.Transform.RotateAt(-(float)CurrentRotation, centerpoint); }