Last active
November 16, 2019 17:04
-
-
Save garganurag893/aa56b7804e374f5722dbe651ecbd48ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {View, Image} from 'react-native'; | |
import {array, object, string} from 'prop-types'; | |
import Matter from 'matter-js'; | |
const water = require('../../assets/water.png'); | |
const Floor = props => { | |
const width = props.size[0]; | |
const height = props.size[1]; | |
const x = props.body.position.x - width / 2; | |
const y = props.body.position.y - height / 2; | |
return ( | |
<View | |
style={[ | |
{ | |
position: 'absolute', | |
left: x, | |
top: y, | |
width: width, | |
height: height, | |
backgroundColor: props.color || 'pink', | |
}, | |
]}> | |
<Image | |
style={{width: width, height: height}} | |
source={water} | |
resizeMode="stretch" | |
/> | |
</View> | |
); | |
}; | |
export default (world, color, pos, size) => { | |
const initialFloor = Matter.Bodies.rectangle( | |
pos.x, | |
pos.y, | |
size.width, | |
size.height, | |
{isStatic: true, friction: 1}, | |
); | |
Matter.World.add(world, [initialFloor]); | |
return { | |
body: initialFloor, | |
size: [size.width, size.height], | |
color: color, | |
renderer: <Floor />, | |
}; | |
}; | |
Floor.propTypes = { | |
size: array, | |
body: object, | |
color: string, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment