public Texture2D BuildTexture2D( RagnarokAnimationPalette Palette, GraphicsDevice Device ) {
			byte[] data = DecodedData();
			Texture2D tex = new Texture2D( Device, Width, Height );
			Color[] colors = new Color[ Width * Height ];

			/*int index;
			for( int x = 0; x < Width; x++ ) {
				for( int y = 0; y < Height; y++ ) {
					index = ( x + ( y * Width ) );
					if( index >= data.Length )
						colors[ index ] = Color.TransparentWhite;
					else
						colors[ index ] = Palette[ data[ index ] ];
				}
			}*/
			for( int i = 0; i < colors.Length; i++ ) {
				// make first index transparent
				if( i >= data.Length || data[ i ] == 0 )
					colors[ i ] = Color.Transparent;
				else
					colors[ i ] = Palette[ data[ i ] ];
			}
			tex.SetData<Color>( colors );

			data = null;
			colors = null;

			return tex;
		}
示例#2
0
		public bool Read( Stream stream ) {
			mReader = new BinaryReader( stream );

			int imgCount = Reader.ReadUInt16();

			// Image Data \\
			mImages = new List<RagnarokAnimationImage>();
			for( int i = 0; i < imgCount; i++ ) {
				mImages.Add( new RagnarokAnimationImage() );
				mImages[ i ].Width = Reader.ReadUInt16();
				mImages[ i ].Height = Reader.ReadUInt16();
				int size = Reader.ReadInt32();
				mImages[ i ].Data = Reader.ReadBytes( size );
			}

			// Palette \\
			mPalette = new RagnarokAnimationPalette( 256 );
			for( int i = 0; i < 256; i++ )
				mPalette.ReadColor( Reader );

			// Actions \\
			mActions = new RagnarokAnimationActionList();
			int actCount = mReader.ReadUInt16();
			for( int i = 0; i < actCount; i++ ) {
				RagnarokAnimationAction action = new RagnarokAnimationAction();
				action.Frames = new RagnarokAnimationActionFrameList();
				int frameCount = mReader.ReadUInt16();
				for( int f = 0; f < frameCount; f++ ) {
					RagnarokAnimationActionFrame frame = new RagnarokAnimationActionFrame();
					frame.Images = new RagnarokAnimationActionFrameImageList();
					frame.Palette1 = mReader.ReadUInt32();
					frame.Palette2 = mReader.ReadUInt32();
					frame.Audio = mReader.ReadInt32();
					frame.Numxxx = mReader.ReadInt32();
					if( frame.Numxxx == 1 ) {
						frame.Ext1 = mReader.ReadInt32();
						frame.ExtX = mReader.ReadInt32();
						frame.ExtY = mReader.ReadInt32();
						frame.Terminate = mReader.ReadInt32();
					}

					int imageCount = mReader.ReadUInt16();
					for( int s = 0; s < imageCount; s++ ) {
						RagnarokAnimationActionFrameImage img = new RagnarokAnimationActionFrameImage() {
							X = mReader.ReadInt16(),
							Y = mReader.ReadInt16(),
							Number = mReader.ReadUInt16(),
							Mirror = mReader.ReadBoolean(),
							Color = new Color( mReader.ReadByte(), mReader.ReadByte(), mReader.ReadByte(), mReader.ReadByte() ),
							ScaleX = mReader.ReadSingle(),
							ScaleY = mReader.ReadSingle(),
							Rotation = mReader.ReadInt16(),
							Type = mReader.ReadInt16(),
							Width = mReader.ReadUInt16(),
							Height = mReader.ReadUInt16(),
						};

						frame.Images.Add( img );
					}
					action.Frames.Add( frame );
				}
				mActions.Add( action );
			}

			// Sounds \\
			mActionSounds = new List<string>();
			int soundCount = Reader.ReadUInt16();
			for( int i = 0; i < soundCount; i++ )
				mActionSounds.Add( Reader.ReadString() );

			return true;
		}