Comments (8)
Thanks for pointing this out! I'm getting a bit more comfortable with TS now, so should be able to review your PR and get it merged ASAP (it might have to wait till after the festive season unfortunately).
Thanks again for your contribution!
from react-native-game-engine.
Also, just wondering where the TS compiler complains?
Would something like this suffice:
<GameEngine entities={{ player: { x: 0, y: 0, renderer: <PlayerRenderer x={0} y={0} /> }}} />
... Or this form, which should also work:
<GameEngine entities={{ player: { x: 0, y: 0, renderer: PlayerRenderer }}} />
from react-native-game-engine.
I have updated the pull request #61 to include a fix for the renderer
property after soliciting some help from Reddit.
from react-native-game-engine.
Awesome @SimpleProgrammingAU, I took a quick look at the PR and it looks really solid. Huge thanks. I'll be 100% back online next week - I'll merge it in then.
from react-native-game-engine.
On a similar front, I am trying to come up with ways to deal with the GameEngine
entities.renderer
property. It accepts a React.Component
object without any props as its value. This invariably leads to either having to make all of the props for each renderer
optional (which means you have to include checks for undefined
) or something else? Not actually sure what best-practice would be in a situation like this.
Hopefully yourself or someone who knows TS better than I can provide a good solution.
from react-native-game-engine.
I see - as in you have written a renderer component and you want to add type safety to the props?
Are you able to use defaultProps
or default values to avoid the null checks whilst still keeping the items in your props interfaces required?
Otherwise, I imagine the challenge will be to overcome the dynamic nature of the GameEngine's
default renderer. Whilst you can switch out the GameEngine's
renderer for something more custom - I'm not quite sure how you would go about that in a type-safe manner.
from react-native-game-engine.
I'll try them both! The first one doesn't feel good having the values entered twice but if the second one works, that is ideal!
Make sure to update the typedefs to allow JSX.element
and React.Component
if either can work =)
from react-native-game-engine.
Using the second option worked perfectly. No issues with the TS-linter.
Thanks heaps for the help! Now I'm just trying to come up with ways to be able to make TS recognise the entities object to have that requirement. I'm gonna have a look and might update my pull request if I work it out.
I tried this but it didn't catch an incorrect value for renderer
:
interface GameEngineEntities {
[key:string | number]: {
[key:string]: any,
renderer?: JSX.Element | React.Component,
}
}
export interface GameEngineProperties {
systems?: any[];
entities?: GameEngineEntities | Promise<any>;
renderer?: any;
touchProcessor?: any;
timer?: DefaultTimer | any;
running?: boolean;
onEvent?: any;
style?: StyleProp<ViewStyle>;
children?: React.ReactNode;
}
Not sure what to try next.
from react-native-game-engine.
Related Issues (20)
- Touch array is empty in iOS HOT 1
- How can i catch in Entity onPress event and value on System.js HOT 3
- Custom fonts used inside GameEngine not working
- Default timer doesn't stop when calling `.stop()` HOT 3
- Nested entity property change doesn't trigger rerender process HOT 3
- How to use TouchEvent for continious handelrs? HOT 1
- Systems functions
- FPS issues HOT 9
- Add animation for moving HOT 10
- Best Way to handle touch as directional control HOT 3
- Support for Expo SDK 43, 44, 45 HOT 7
- Cant handle multitouch operations and it is really slow HOT 4
- How to change Game Engine's coordinate ?
- Tilemap free pan
- while dragging create line like WordSearch game
- What type of game can i build???
- is there anyone who is maintaining this library yet? HOT 2
- GameEngine re-rendering on entities change HOT 3
- Types not importing; not a real fix, but raising the issue HOT 1
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 react-native-game-engine.