react-native-game-engine-ex.../game/systems/GameLoop.ts

24 lines
755 B
TypeScript
Raw Normal View History

2022-06-25 00:29:43 -05:00
import Matter, { Vector } from "matter-js";
import { GameEngineUpdateEventOptionType, TouchEvent } from "react-native-game-engine";
import { windowHeight, windowWidth } from "@game";
export const GameLoop = (
entities: any,
{ touches, time, dispatch }: GameEngineUpdateEventOptionType
) => {
let engine = entities.physics.engine;
let world = entities.physics.world;
touches
.filter((t: TouchEvent) => t.type === "press")
.forEach((t: TouchEvent) => {
let balloonPos = entities.Balloon.body.position;
console.log('Touch:', t, balloonPos);
// Matter.Body.setVelocity(something, { x: something.velocity.x + 20, y: something.velocity.y - 20 });
});
Matter.Engine.update(engine, time.delta);
return entities;
};