Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Jawnnypoo/PhysicsLayout
Android layout that simulates physics using JBox2D
https://github.com/Jawnnypoo/PhysicsLayout
android box2d jbox2d layout physics view
Last synced: about 2 months ago
JSON representation
Android layout that simulates physics using JBox2D
- Host: GitHub
- URL: https://github.com/Jawnnypoo/PhysicsLayout
- Owner: Jawnnypoo
- License: apache-2.0
- Created: 2015-04-10T05:31:35.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-01-17T09:58:15.000Z (11 months ago)
- Last Synced: 2024-10-04T09:56:25.112Z (2 months ago)
- Topics: android, box2d, jbox2d, layout, physics, view
- Language: Kotlin
- Size: 1.5 MB
- Stars: 772
- Watchers: 29
- Forks: 102
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- -awesome-android-ui - PhysicsLayout - 2.0) | <img src="/art/PhysicsLayout.gif" width="49%"> (Index `(light-weight pages)`)
- awesome-android-ui - PhysicsLayout - 2.0) | <img src="/art/PhysicsLayout.gif" width="49%"> (Index `(light-weight pages)`)
- awesome-kotlin - PhysicsLayout - Android layout that simulates physics using JBox2D (Libraries)
- awesome-android-ui - PhysicsLayout - 2.0) | <img src="/art/PhysicsLayout.gif" width="49%"> (Index)
- awesome-android-ui - https://github.com/Jawnnypoo/PhysicsLayout
- awesome-android-ui - https://github.com/Jawnnypoo/PhysicsLayout
README
# PhysicsLayout
Android layout that simulates physics using [JBox2D](https://github.com/jbox2d/jbox2d). Simply add views, enable physics, and watch them fall!See it in action with the sample app:
[![Google Play](https://raw.githubusercontent.com/Jawnnypoo/PhysicsLayout/master/art/google-play-badge.png)](https://play.google.com/store/apps/details?id=com.jawnnypoo.physicslayout.sample)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jawnnypoo/physicslayout/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jawnnypoo/physicslayout)
## Gradle
```groovy
dependencies {
implementation("com.jawnnypoo:physicslayout:latest.release.here")
}
```## Basic Usage
If you want to see what your layout looks like when physics is applied to it, simply change your root layout to a physics layout.
```xml
```
## Custom XML Attributes
You can also further customize the behaviour of your PhysicsLayout
```xml```
* `physics` boolean, Determines if physics will be applied to the layout (Default true)
* `gravityX` float, Sets the gravity in the X direction (positive is right, negative is left) (Default 0)
* `gravityY` float, Sets the gravity in the Y direction (positive is down, negative is up) (Default 9.8)
* `bounds` boolean, Determines if the layout should have bounds on the edges of itself (Default true)
* `boundsSize` dimenstion, Sets the width/height of the bounds on the edges (Default 20dp)## Custom Physics Configuration
Each view contained within the layout has a physics configuration that it uses to create itself in the Box2D world. This defines its shape, mass, restitutaion, and other physics related variables. A custom configuration can be applied to each view as well:
```xml```
or alternatively, the Physics definition can be made programmatically:
```kotlin
val circleView = findViewById(R.id.circle)
val config = PhysicsConfig(
shape = Shape.CIRCLE,
fixtureDef = fixtureDef,
bodyDef = bodyDef
)
Physics.setPhysicsConfig(circleView, config)
```This is useful especially if you have view that would be considered circular, as the default for all views is a RECTANGLE shape. Most of the time, if you are just dealing with rectangular views, the defaults will work for you and you will not have to worry about this.
Check out the sample app to see most of these things in action.
## Making a Game?
This library was designed with the intention of allowing for playful animations within normal Android apps. It is not built to be a game engine or meant to compete with the likes. If you are looking to do more intense mobile games, we recommend libraries such as [libGDX](https://libgdx.badlogicgames.com/) or [Unity](https://unity3d.com/)License
--------Copyright 2024 John Carlson
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.