// Methods public void syncCharacter() { if (this.c == null || this.position == null) { return; } this.c.x = FloatToInt(this.position.x, eRoundNearest); this.c.y = FloatToInt(this.position.y, eRoundNearest); int angle = FloatToInt(Maths.RadiansToDegrees(this.direction.angle()), eRoundNearest); angle = angle - this.carSpriteAngle; angle = Maths.Angle360(angle); if (this.sprite == null || angle != this.currentSpriteRotation) { if (angle != 0) { DynamicSprite spr = DynamicSprite.CreateFromExistingSprite(this.carSprite, true); spr.Rotate(angle); this.sprite = spr; this.viewFrame.Graphic = this.sprite.Graphic; } else { this.sprite = null; this.viewFrame.Graphic = this.carSprite; } this.currentSpriteRotation = angle; } int yoff = (Game.SpriteHeight[this.viewFrame.Graphic] - Game.SpriteHeight[this.carSprite]) / 2; yoff += Game.SpriteHeight[this.carSprite] / 2; this.c.LockViewOffset(this.viewFrame.View, 0, yoff); this.c.Loop = this.viewFrame.Loop; this.c.Frame = this.viewFrame.Frame; }
public static DynamicSprite[] CreateLoop(int view, int loop, int base_loop = 0) { if (loop == base_loop || view >= Game.ViewCount || loop >= Game.GetLoopCountForView(view) || base_loop >= Game.GetLoopCountForView(view)) { return(null); } int rot_angle = LoopAngles[loop] - LoopAngles[base_loop]; rot_angle = Maths.Angle360(rot_angle); int frame = 0; int base_frame_count = Game.GetFrameCountForLoop(view, base_loop); int dest_frame_count = Game.GetFrameCountForLoop(view, loop); int frame_count = Maths.Max(base_frame_count, dest_frame_count); DynamicSprite[] sprarr = new DynamicSprite[frame_count]; for (frame = 0; frame < frame_count; frame += 1) { ViewFrame vf = Game.GetViewFrame(view, base_loop, frame); DynamicSprite spr = DynamicSprite.CreateFromExistingSprite(vf.Graphic); spr.Rotate(rot_angle); vf = Game.GetViewFrame(view, loop, frame); vf.Graphic = spr.Graphic; sprarr[frame] = spr; } return(sprarr); }
public void SyncCharacter() { if (this.c == null || this.position == null) { return; } this.c.x = FloatToInt(this.position.x, eRoundNearest); this.c.y = FloatToInt(this.position.y, eRoundNearest); if (this.c.Room != player.Room) { this.c.ChangeRoom(player.Room); } int angle = FloatToInt(Maths.RadiansToDegrees(this.direction.angle()), eRoundNearest); angle = angle - this.carSpriteAngle; angle = Maths.Angle360(angle); if (this.dSprite == null || angle != this.dSpriteRotation) { // Optimisation - Don't delete old sprite //if (this.dSprite != null) // this.dSprite.Delete(); if (angle != 0) { // NEW (keep drawing surface) DynamicSprite spr = this.dSprite; if (spr == null) { spr = DynamicSprite.CreateFromExistingSprite(this.carSprite, true); } // OLD //DynamicSprite spr = DynamicSprite.CreateFromExistingSprite(this.carSprite, true); spr.Rotate(angle); this.dSprite = spr; this.viewFrame.Graphic = this.dSprite.Graphic; //DrawingSurface ds = this.dSprite.GetDrawingSurface(); //ds.DrawPixel(-1, -1); //ds.Release(); } else { this.dSprite = null; this.viewFrame.Graphic = this.carSprite; } this.dSpriteRotation = angle; } int yoff = (Game.SpriteHeight[this.viewFrame.Graphic] - Game.SpriteHeight[this.carSprite]) / 2; yoff += Game.SpriteHeight[this.carSprite] / 2; this.c.LockViewOffset(this.viewFrame.View, 0, yoff); this.c.Loop = this.viewFrame.Loop; this.c.Frame = this.viewFrame.Frame; }