Skip to content

Instantly share code, notes, and snippets.

Avatar

Limes2018 flushpot1125

View GitHub Profile
View bjs_es6_webpack.config.js
//参考:https://qiita.com/10mi8o/items/2477f2640291f0ce6687
/* pathモジュールを使ってwebページとして出力するパスを指定する。
"path.resolveは、引数をつなげて絶対パスに変換する"
"__dirname"は、実行集のソースコードが格納されているディレクトリパス
参考:https://gist.github.com/uupaa/da42698d6b2d2cbb3cca
*/
const path = require('path');
//const outputPath = path.resolve(__dirname, 'dist');
View modified_index.html
<!-- <script src="./node_modules/cannon/build/cannon.js" type="text/javascript"></script> -->
<!-- you should drag and drop cannon.js file -->
<script src="./cannon.js" type="text/javascript"></script>
View call_other_class_method_example.ts
//ball.ts
import { Mesh} from "@babylonjs/core";
import GameComponent from "./game";
export default class BallComponent extends Mesh {
public _scene: GameComponent;
//...
/**
* Called each frame.
View gui_example.ts
import { AdvancedDynamicTexture, TextBlock, Control, Image, StackPanel } from "@babylonjs/gui";
/**
* Defines the reference to the GUI advanced texture.
*/
public gui: AdvancedDynamicTexture = null;
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
View keycodevent2_example.ts
/**
* Registers the keyboard event to start game.
*/
private _registerStartGameEvent(): void {
// Register the space keyboard event to start the game.
const spaceObservable = this.onKeyboardObservable.add((ev) => {
if (ev.event.keyCode === 32) { // space bar
this._ball.reset();
this._ball.applyStartImpulse();
View collision_example.ts
import { Mesh, PhysicsImpostor } from "@babylonjs/core";
export default class BlockComponent extends Mesh {
// ...
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
public onInitialize(): void {
this.physicsImpostor = new PhysicsImpostor(this, PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0, restitution: 1 });
View physics_example.ts
import { Mesh, PhysicsImpostor, Vector3 } from "@babylonjs/core";
export default class BallComponent extends Mesh {
//...
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
public onInitialize(): void {
View keycodevent_example.ts
import { onKeyboardEvent } from "../tools";
export default class PlayerComponent extends Mesh {
// ...
/*
* An example of keycode reference : https://keycode.info/
*/
/**
* Moves the player on the left
*/
@onKeyboardEvent(65, KeyboardEventTypes.KEYDOWN)
View template_bjseditorv4.ts
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
public onInitialize(): void {
// ...
}
/**
* Called on the scene starts.
View gsap_cube_motion.ts
import {Mesh } from "@babylonjs/core";
import {gsap} from "gsap";
export default class CubeComponent extends Mesh {
public onStart(): void {
// other example
/*
gsap.to(this.rotation, {y:12, x:5, duration:4, repeat:-1, yoyo:true})
gsap.to(this.position, {x:5, duration:4, repeat:-1, yoyo:true})
gsap.to(this.scaling, {y:0.5, duration:2, repeat:-1, yoyo:true})
*/
You can’t perform that action at this time.