Socket
Socket
Sign inDemoInstall

gmr

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

camera.js

22

gmr.js

@@ -0,1 +1,2 @@

import gmrCamera from './camera.js'
import gmrCanvas from './canvas.js'

@@ -20,2 +21,4 @@ import gmrImgManager from './img-manager.js'

container.appendChild( ui )
const camera = gmrCamera()
let currentScene

@@ -32,2 +35,3 @@ let renderLoop = gmrRenderLoop(constant)

const openScene = scene => {
currentScene = scene
imgManager.switchScene( scene )

@@ -64,2 +68,12 @@ imgManager.onSceneLoad(() => {

const zoom = val => {
camera.setZoom(val)
currentScene.updateUI()
}
const pan = (x, y) => {
camera.setPosition(x, y)
currentScene.updateUI()
}
const cameraPosition = camera.getPosition
return {

@@ -69,8 +83,10 @@ container, canvas, imgManager, ui, constant,

scene: init => gmrScene(constant, imgManager, init),
prefab: (name, fn, ...animations) => gmrPrefab(constant, canvas.el, ui, name, fn, ...animations),
sprite: () => gmrSprite(constant, canvas.el, ui),
behavior: gmrBehavior, ...keyManager
prefab: (name, fn, ...animations) => gmrPrefab(constant, canvas.el, ui, camera, name, fn, ...animations),
sprite: () => gmrSprite(constant, canvas.el, ui, camera),
behavior: gmrBehavior, ...keyManager,
zoom, pan, cameraPosition
}
}
export default setup

@@ -77,0 +93,0 @@

8

img-manager.js
import loadScreen from "./load-screen.js"
let el
export default () => {
const el = document.createElement('div')
el.classList.add('gmr-img-manager')
if(!el) {
el = document.createElement('div')
el.classList.add('gmr-img-manager')
}

@@ -7,0 +11,0 @@ let expected = 0

{
"name": "gmr",
"version": "0.1.0",
"version": "0.2.0",
"description": "js 2d canvas engine",

@@ -5,0 +5,0 @@ "main": "gmr.js",

import sprite from "./sprite.js"
export default (constant, canvas, ui, name, fn, ...animations) => {
export default (constant, canvas, ui, camera, name, fn, ...animations) => {
const newSprite = (...bounds) => {
const spriteObj = sprite(constant, canvas, ui)
const spriteObj = sprite(constant, canvas, ui, camera)
animations.forEach(animation =>

@@ -7,0 +7,0 @@ spriteObj.addAnimation(...animation)

@@ -59,2 +59,8 @@ export default (constant, imgManager, init) => {

const onPostRender = fn => postRenderFN = fn
const updateUI = () => {
sprites.forEach(sprite => {
sprite.updateUI()
})
}

@@ -64,3 +70,3 @@ const exportable = {

load, onPreRender, onPostRender,
addPrefab, removePrefab, spawn
addPrefab, removePrefab, spawn, updateUI
}

@@ -67,0 +73,0 @@ if(init) init(exportable)

@@ -1,2 +0,2 @@

export default (constant, canvas, ui) => {
export default (constant, canvas, ui, camera) => {
let animations = {}

@@ -77,6 +77,6 @@ let index = 0, animationPriority = 0

animations[currentAnimation][index],
bounds.x,
bounds.y,
bounds.width,
bounds.height
bounds.x * camera.getZoom() + camera.getPosition().x,
bounds.y * camera.getZoom() + camera.getPosition().y,
bounds.width * camera.getZoom(),
bounds.height * camera.getZoom()
)

@@ -87,6 +87,6 @@ else

animations[currentAnimation][index],
-bounds.x,
bounds.y,
bounds.width,
bounds.height,
-bounds.x * camera.getZoom() - camera.getPosition().x,
bounds.y * camera.getZoom() + camera.getPosition().y,
bounds.width * camera.getZoom(),
bounds.height * camera.getZoom(),
true

@@ -97,6 +97,6 @@ )

engine.drawOutline(
bounds.x,
bounds.y,
bounds.width,
bounds.height
bounds.x * camera.getZoom() + camera.getPosition().x,
bounds.y * camera.getZoom() + camera.getPosition().y,
bounds.width * camera.getZoom(),
bounds.height * camera.getZoom()
)

@@ -217,3 +217,3 @@ }

x: x * (screenBounds.width / constant.RESOLUTION[0]),
y: y * (screenBounds.height / constant.RESOLUTION[1]),
y: y * (screenBounds.height / constant.RESOLUTION[1])
}

@@ -246,7 +246,8 @@ }

}
el.style.top = scale(0, bounds.y + offset.y).y + 'px'
el.style.left = scale(bounds.x + offset.x, 0).x + 'px'
el.style.width = scale(bounds.width + offset.width, 0).x + 'px'
el.style.height = scale(0, bounds.height + offset.height).y + 'px'
el.style.top = scale(0, bounds.y + offset.y).y * camera.getZoom() + scale(0, camera.getPosition().y).y + 'px'
el.style.left = scale(bounds.x + offset.x, 0).x * camera.getZoom() + scale(camera.getPosition().x, 0).x + 'px'
el.style.width = scale(bounds.width + offset.width, 0).x * camera.getZoom() + 'px'
el.style.height = scale(0, bounds.height + offset.height).y * camera.getZoom() + 'px'
})
sprites.forEach(sprite => sprite.updateUI())
}

@@ -253,0 +254,0 @@ const getUI = id => elements[id]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc