0.0.5 • Published 7 years ago

react-native-physics v0.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

react-native-physics

A physics library for React Native (in progress)

npm.io

youtube video that shows all the examples

Installation

npm install --save react-native-physics

Importation

import { Container, Box } from 'react-native-physics';

Usagation

Container lays out just like a View. Container holds the state of each box. Put Boxes inside the Container.

Examplelation

render() {
    return (
      <Container
        style={{ flex: 1, backgroundColor: '#fff' }}
        delay={500}
        >
        <Box
          position={{ x: 20, y: 150 }}
          velocity={{ x: 5, y: -7 }}
          bounce={{ x: 1, y: 1 }}
          collideWithContainer={true}
          id="a"
          >
          <Text style={{ fontSize: 35 }}>Hello World</Text>
        </Box>
      </Container>
    );
  }

To run the example in this repository, git clone, npm install, and react-native run-ios (or run-android).

Props

Container

Propertytypedefaultrequired
heightnumbernullfalse
widthnumbernullfalse
fpsnumber60false
delaynumber0false
collidearray of objectsnullfalse
overlaparray of objectsnullfalse

Note: collide and overlap array objects must follow this protocol

{
  boxes: [/* strings of box IDs */],
  callback: () => {} // box1, box2 are passed as arguments
}

Box

Propertytypedefaultrequired
positionobject{ x: 0, y: 0 }false
gravityobject{ x: 0, y: 0 }false
velocityobject{ x: 0, y: 0 }false
accelerationobject{ x: 0, y: 0 }false
dragobject{ x: 0, y: 0 }false
heightnumbernullfalse
widthnumbernullfalse
outlineboolean or stringnullfalse
collideWithContainerbooleanfalsefalse
idstring or numbernulltrue

Note: If outline is set to true, the outline will be red. If set to a string, it must be a valid color (i.e. 'blue', '#abc', '#88dd66', 'rgb(...)', 'rgba(...)')

Contributing

Please do so. School and other projects have shifted my focus away from this one. Note: The developer experience was intended to be similar to Phaser and the logic of physics is loosely based on this article.