57장 에니메이션 동작 방식 (사각형 움직이기)
![]() - 정지된 그림을 빠른 시간에 여러 장 보여줌으로써 마치 움직이는 것 같은 효과를 나타내는 기법을 사용 - 여러 프레임이 모여 하나의 애니메이션을 이루는 구조를 가지고 있으며, Adobe사의 Flash는 만화 영화의 방식과 같이 하나하나의 프레임을 디자이너가 제작해서 애니메이션 작성 가능 |
![]() <UserControl x:Class="AnimationExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Canvas x:Name="LayoutRoot"> <Canvas.Resources> <!-- 사각형을 이동 시키는 스토리 보드 --> <Storyboard x:Name="rectAnimation"> <!-- Y 좌표 이동 에니메이션 --> <DoubleAnimation Storyboard.TargetName="rect" Storyboard.TargetProperty="(Canvas.Top)" From="0" To="100"/> <!-- X 좌표 이동 에니메이션 --> <DoubleAnimation Storyboard.TargetName="rect" Storyboard.TargetProperty="(Canvas.Left)" From="0" To="100"/> </Storyboard> </Canvas.Resources> <!-- 사각형 --> <Rectangle x:Name="rect" Fill="Red" Width="100" Height="100" Canvas.Left="0" Canvas.Top="0"/> </Canvas> </UserControl> |
![]() using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace AnimationExample { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); rect.MouseLeftButtonDown += new MouseButtonEventHandler(MouseLeftButtonDown_Handler); } void MouseLeftButtonDown_Handler(object sender, MouseButtonEventArgs e) { // 애니메이션 시작 rectAnimation.Begin(); } } } |