Comments (3)
@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.
@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.
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)
- [Orbit game] Enable a sketch mode for rendering
- Reorganise things HOT 1
- Introduce mocks to reduce friction for unit testing
- Orbit Not compiling for windows HOT 10
- Setup CI/CD pipeline HOT 1
- Investigate dynamic creation of scenes
- Investigate a need for Scoped lifetimes
- Find the best way to load images
- Consider better name before first release HOT 1
- Investigate the use of some level of snapshot testing
- Investigate and add in better lifecycle support for game entities
- Let's get physics all HOT 2
- Consider adding a image resource container to image load management HOT 14
- Deployment and Usability HOT 1
- Really simple sample HOT 2
- Please update to .NET 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orbit.