Giter VIP home page Giter VIP logo

Comments (3)

bijington avatar bijington commented on July 17, 2024 2

@paramsaggu thank you for this update. Does this change prevent the possible COM exceptions that is mentioned here? dotnet/Microsoft.Maui.Graphics#422 (comment) I am definitely keen to follow this issue. I do believe the actual PlatformImage option on Windows should be coming in the not so distant future (I am hoping for .NET 7.0) meaning we can avoid having to do this workaround.

I like the idea of Lazy loading! We are actually discussing how to improve the efficiency around loading images and sharing them over at #19 so this could really help that!

from orbit.

paramsaggu avatar paramsaggu commented on July 17, 2024 1

@bijington I have committed the changes in the fork of this repository. And recently I found that if you load images after GameView is Loaded, the GlobalCreator will automatically get initialized.
You can have a look at the changes here:
main...paramsaggu:orbit:windows-com-exception-fixed

from orbit.

paramsaggu avatar paramsaggu commented on July 17, 2024

Hi @bijington, I have done a little workaround for the windows environment.

Here is the updated GameSceneView class that will handle the missing GlobalCreator initialization:

public partial class GameSceneView : GraphicsView
{
    public GameSceneView()
    {
        BackgroundColor = Colors.Transparent;
#if WINDOWS
        Loaded += GameSceneView_Loaded;
    }

    private void GameSceneView_Loaded(object sender, EventArgs e)
    {
        System.Reflection.Assembly assembly = typeof(Microsoft.Maui.Graphics.Win2D.W2DCanvas).Assembly;
        var type = assembly.GetType("Microsoft.Maui.Graphics.Win2D.W2DGraphicsService");
        var prop = type.GetProperty("GlobalCreator");

        var graphicsView = (GraphicsView)sender;
        var view = (Microsoft.Maui.Platform.PlatformTouchGraphicsView)graphicsView.Handler.PlatformView;
        var view2 = (Microsoft.Maui.Graphics.Win2D.W2DGraphicsView)view.Content;
        prop.SetValue(null, view2.Content);
        }
#else
    }
#endif

    private IGameScene scene;

    public IGameScene Scene
    {
        get => scene;
        internal set
        {
            scene = value;
            Drawable = value;
        }
    }
}

Also you can make the image loading Lazy like this:

public class Asteroid : GameObject
{
    private readonly IGameSceneManager gameSceneManager;
    Lazy<Microsoft.Maui.Graphics.IImage> image;
    float x;
    float y;
    Movement movement;

    public Asteroid(IGameSceneManager gameSceneManager)
    {
        image = new Lazy<Microsoft.Maui.Graphics.IImage>(()=> LoadImage("asteroid.png"));

        this.gameSceneManager = gameSceneManager;
    }
}

from orbit.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.