Пример #1
0
    public static ISprite Create(
        string textureKey,
        string frameKey,
        Point position,
        SpriteOptions options,
        IJSInProcessRuntime jsRuntime)
    {
        var spriteKey = Guid.NewGuid().ToString();
        List <IDisposable> disposables = new();

        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerDownRef = null;
        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerOutRef  = null;
        DotNetObjectReference <PhaserCallback <Point, Task> >?onPointerOverRef = null;

        if (options.OnPointerDown is not null)
        {
            onPointerDownRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerDown));

            disposables.Add(onPointerDownRef);
        }

        if (options.OnPointerOut is not null)
        {
            onPointerOutRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerOut));

            disposables.Add(onPointerOutRef);
        }

        if (options.OnPointerOver is not null)
        {
            onPointerOverRef = DotNetObjectReference.Create(
                new PhaserCallback <Point, Task>(options.OnPointerOver));

            disposables.Add(onPointerOverRef);
        }

        var size = jsRuntime.Invoke <Size>(
            PhaserConstants.Functions.AddSprite,
            spriteKey,
            textureKey,
            frameKey,
            position,
            options.Origin,
            options.Depth,
            onPointerDownRef,
            onPointerOutRef,
            onPointerOverRef,
            options.ScrollFactor);

        return(new PhaserSprite(
                   spriteKey,
                   position,
                   size,
                   frameKey,
                   disposables,
                   jsRuntime));
    }
Пример #2
0
 /// <summary>
 /// <p>Renders part or all of the given sprite batch to the device context using the specified drawing options.</p>
 /// </summary>
 /// <param name="spriteBatch"><dd>  <p>The sprite batch to draw.</p> </dd></param>
 /// <param name="startIndex"><dd>  <p>The index of the first sprite in the sprite batch to draw.</p> </dd></param>
 /// <param name="spriteCount"><dd>  <p>The number of sprites to draw.</p> </dd></param>
 /// <param name="bitmap"><dd>  <p>The bitmap from which the sprites are to be sourced. Each sprite?s source rectangle refers to a portion of this bitmap.</p> </dd></param>
 /// <param name="interpolationMode"><dd>  <p>The interpolation mode to use when drawing this sprite batch. This determines how Direct2D interpolates pixels within the drawn sprites if scaling is performed.</p> </dd></param>
 /// <param name="spriteOptions"><dd>  <p>The additional drawing options, if any, to be used for this sprite batch.</p> </dd></param>
 /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1CommandSink3::DrawSpriteBatch']/*"/>
 /// <msdn-id>mt619823</msdn-id>
 /// <unmanaged>HRESULT ID2D1CommandSink3::DrawSpriteBatch([In] ID2D1SpriteBatch* spriteBatch,[In] unsigned int startIndex,[In] unsigned int spriteCount,[In] ID2D1Bitmap* bitmap,[In] D2D1_BITMAP_INTERPOLATION_MODE interpolationMode,[In] D2D1_SPRITE_OPTIONS spriteOptions)</unmanaged>
 /// <unmanaged-short>ID2D1CommandSink3::DrawSpriteBatch</unmanaged-short>
 public void DrawSpriteBatch(SpriteBatch spriteBatch,
                             int startIndex,
                             int spriteCount,
                             Bitmap bitmap,
                             BitmapInterpolationMode interpolationMode,
                             SpriteOptions spriteOptions)
 {
     DrawSpriteBatch_(spriteBatch, startIndex, spriteCount, bitmap, interpolationMode, spriteOptions);
 }
Пример #3
0
 /// <summary>	
 /// <p>Renders part or all of the given sprite batch to the device context using the specified drawing options.</p>	
 /// </summary>	
 /// <param name="spriteBatch"><dd>  <p>The sprite batch to draw.</p> </dd></param>	
 /// <param name="startIndex"><dd>  <p>The index of the first sprite in the sprite batch to draw.</p> </dd></param>	
 /// <param name="spriteCount"><dd>  <p>The number of sprites to draw.</p> </dd></param>	
 /// <param name="bitmap"><dd>  <p>The bitmap from which the sprites are to be sourced. Each sprite?s source rectangle refers to a portion of this bitmap.</p> </dd></param>	
 /// <param name="interpolationMode"><dd>  <p>The interpolation mode to use when drawing this sprite batch. This determines how Direct2D interpolates pixels within the drawn sprites if scaling is performed.</p> </dd></param>	
 /// <param name="spriteOptions"><dd>  <p>The additional drawing options, if any, to be used for this sprite batch.</p> </dd></param>	
 /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>	
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1CommandSink3::DrawSpriteBatch']/*"/>	
 /// <msdn-id>mt619823</msdn-id>	
 /// <unmanaged>HRESULT ID2D1CommandSink3::DrawSpriteBatch([In] ID2D1SpriteBatch* spriteBatch,[In] unsigned int startIndex,[In] unsigned int spriteCount,[In] ID2D1Bitmap* bitmap,[In] D2D1_BITMAP_INTERPOLATION_MODE interpolationMode,[In] D2D1_SPRITE_OPTIONS spriteOptions)</unmanaged>	
 /// <unmanaged-short>ID2D1CommandSink3::DrawSpriteBatch</unmanaged-short>	
 public void DrawSpriteBatch(SpriteBatch spriteBatch,
     int startIndex,
     int spriteCount,
     Bitmap bitmap,
     BitmapInterpolationMode interpolationMode,
     SpriteOptions spriteOptions)
 {
     DrawSpriteBatch_(spriteBatch, startIndex, spriteCount, bitmap, interpolationMode, spriteOptions);
 }