-
Notifications
You must be signed in to change notification settings - Fork 31
added apply_linear_impulse example #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e8be029
Added Defold 1.12.3 CONSTANT_TYPE_TIME example
JuLongZhiLu d153bc5
Merge branch 'master' of https://github.com/JuLongZhiLu/examples
JuLongZhiLu 180c588
added apply_linear_impluse example
JuLongZhiLu 2d4f739
changed clear color and font, added kenney physics assets
JuLongZhiLu 6b14ae7
Update thumbnail.png
JuLongZhiLu 7ac3025
impluse -> impulse
JuLongZhiLu 744affa
folder name: impluse -> impulse
JuLongZhiLu 76385c6
game.project: impluse -> impulse
JuLongZhiLu 98f5d82
Added more info about the script and Box2D API.
paweljarosz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| tags: physics | ||
| title: Apply Linear Impluse | ||
| brief: This example demonstrates how to apply linear impluse to a dynamic cube on touch/click | ||
| author: JuLongZhiLu(巨龙之路) | ||
| scripts: cube.script | ||
| thumbnail: thumbnail.png | ||
| --- | ||
|
|
||
| The cube contains a dynamic collisionobject component. | ||
|
|
||
|  | ||
|
|
||
| The below script applies a vertical linear impulse to the dynamic collisionobject on click/touch using the `b2d` API functions. | ||
|
|
||
| Read more about the [Box2D API here](https://defold.com/ref/stable/b2d-lua/). | ||
Binary file not shown.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| font: "/fonts/SourceSansPro-Semibold.ttf" | ||
| material: "/builtins/fonts/font-df.material" | ||
| size: 32 | ||
| output_format: TYPE_DISTANCE_FIELD | ||
| characters: " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [bootstrap] | ||
| main_collection = /scenes/main.collectionc | ||
|
|
||
| [script] | ||
| shared_state = 1 | ||
|
|
||
| [display] | ||
| width = 960 | ||
| height = 640 | ||
| high_dpi = 1 | ||
|
|
||
| [android] | ||
| input_method = HiddenInputField | ||
|
|
||
| [physics] | ||
| gravity_y = -1000.0 | ||
| scale = 0.01 | ||
| use_fixed_timestep = 1 | ||
|
|
||
| [html5] | ||
| scale_mode = stretch | ||
|
|
||
| [project] | ||
| title = defold-apply_linear_impulse-example | ||
|
|
||
| [render] | ||
| clear_color_red = 0.160156 | ||
| clear_color_green = 0.164063 | ||
| clear_color_blue = 0.183594 | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| mouse_trigger { | ||
| input: MOUSE_BUTTON_1 | ||
| action: "touch" | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| name: "main" | ||
| scale_along_z: 0 | ||
| embedded_instances { | ||
| id: "cube" | ||
| data: "components {\n" | ||
| " id: \"cube\"\n" | ||
| " component: \"/scripts/cube.script\"\n" | ||
| "}\n" | ||
| "embedded_components {\n" | ||
| " id: \"sprite\"\n" | ||
| " type: \"sprite\"\n" | ||
| " data: \"default_animation: \\\"elementStone011\\\"\\n" | ||
| "material: \\\"/builtins/materials/sprite.material\\\"\\n" | ||
| "size {\\n" | ||
| " x: 60.0\\n" | ||
| " y: 60.0\\n" | ||
| "}\\n" | ||
| "size_mode: SIZE_MODE_MANUAL\\n" | ||
| "textures {\\n" | ||
| " sampler: \\\"texture_sampler\\\"\\n" | ||
| " texture: \\\"/textures/textures.atlas\\\"\\n" | ||
| "}\\n" | ||
| "\"\n" | ||
| "}\n" | ||
| "embedded_components {\n" | ||
| " id: \"collisionobject\"\n" | ||
| " type: \"collisionobject\"\n" | ||
| " data: \"type: COLLISION_OBJECT_TYPE_DYNAMIC\\n" | ||
| "mass: 1.0\\n" | ||
| "friction: 0.1\\n" | ||
| "restitution: 0.5\\n" | ||
| "group: \\\"default\\\"\\n" | ||
| "mask: \\\"default\\\"\\n" | ||
| "embedded_collision_shape {\\n" | ||
| " shapes {\\n" | ||
| " shape_type: TYPE_BOX\\n" | ||
| " position {\\n" | ||
| " }\\n" | ||
| " rotation {\\n" | ||
| " }\\n" | ||
| " index: 0\\n" | ||
| " count: 3\\n" | ||
| " }\\n" | ||
| " data: 30.0\\n" | ||
| " data: 30.0\\n" | ||
| " data: 10.0\\n" | ||
| "}\\n" | ||
| "\"\n" | ||
| "}\n" | ||
| "" | ||
| position { | ||
| x: 480.0 | ||
| y: 351.0 | ||
| } | ||
| } | ||
| embedded_instances { | ||
| id: "platform" | ||
| data: "embedded_components {\n" | ||
| " id: \"sprite\"\n" | ||
| " type: \"sprite\"\n" | ||
| " data: \"default_animation: \\\"elementStone013\\\"\\n" | ||
| "material: \\\"/builtins/materials/sprite.material\\\"\\n" | ||
| "slice9 {\\n" | ||
| " x: 50.0\\n" | ||
| " z: 50.0\\n" | ||
| "}\\n" | ||
| "size {\\n" | ||
| " x: 400.0\\n" | ||
| " y: 70.0\\n" | ||
| "}\\n" | ||
| "size_mode: SIZE_MODE_MANUAL\\n" | ||
| "textures {\\n" | ||
| " sampler: \\\"texture_sampler\\\"\\n" | ||
| " texture: \\\"/textures/textures.atlas\\\"\\n" | ||
| "}\\n" | ||
| "\"\n" | ||
| "}\n" | ||
| "embedded_components {\n" | ||
| " id: \"collisionobject\"\n" | ||
| " type: \"collisionobject\"\n" | ||
| " data: \"type: COLLISION_OBJECT_TYPE_STATIC\\n" | ||
| "mass: 0.0\\n" | ||
| "friction: 0.1\\n" | ||
| "restitution: 0.5\\n" | ||
| "group: \\\"default\\\"\\n" | ||
| "mask: \\\"default\\\"\\n" | ||
| "embedded_collision_shape {\\n" | ||
| " shapes {\\n" | ||
| " shape_type: TYPE_BOX\\n" | ||
| " position {\\n" | ||
| " }\\n" | ||
| " rotation {\\n" | ||
| " }\\n" | ||
| " index: 0\\n" | ||
| " count: 3\\n" | ||
| " }\\n" | ||
| " data: 200.0\\n" | ||
| " data: 35.0\\n" | ||
| " data: 10.0\\n" | ||
| "}\\n" | ||
| "\"\n" | ||
| "}\n" | ||
| "" | ||
| position { | ||
| x: 480.0 | ||
| y: 272.0 | ||
| } | ||
| } | ||
| embedded_instances { | ||
| id: "label" | ||
| data: "embedded_components {\n" | ||
| " id: \"label\"\n" | ||
| " type: \"label\"\n" | ||
| " data: \"size {\\n" | ||
| " x: 128.0\\n" | ||
| " y: 32.0\\n" | ||
| "}\\n" | ||
| "text: \\\"Click to apply linear impulse to the cube\\\"\\n" | ||
| "font: \\\"/fonts/text32.font\\\"\\n" | ||
| "material: \\\"/builtins/fonts/label-df.material\\\"\\n" | ||
| "\"\n" | ||
| " position {\n" | ||
| " x: 480.0\n" | ||
| " y: 435.0\n" | ||
| " }\n" | ||
| "}\n" | ||
| "" | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| function init(self) | ||
| msg.post(".", "acquire_input_focus") | ||
| end | ||
|
|
||
| function on_input(self, action_id, action) | ||
| if action_id == hash("touch") and action.pressed then | ||
| -- get the b2body object | ||
| local body = b2d.get_body("#collisionobject") | ||
|
|
||
| -- add an impluse | ||
| local pos = b2d.body.get_position(body) | ||
| b2d.body.apply_linear_impulse(body, vmath.vector3(0,600,0), pos) | ||
| end | ||
| end | ||
|
|
||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| images { | ||
| image: "/textures/pixel.png" | ||
| } | ||
| images { | ||
| image: "/textures/elementStone011.png" | ||
| } | ||
| images { | ||
| image: "/textures/elementStone013.png" | ||
| } | ||
| extrude_borders: 2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.