@@ -49,7 +49,7 @@ function sprite(options) {
4949 sprite . texture . src = "assets/textures/" + url ;
5050 } else {
5151 sprite . texture = null
52- sprite . size = { x :0 , y :0 }
52+ if ( sprite . size == null ) { sprite . size = { x :0 , y :0 } }
5353 }
5454 }
5555
@@ -97,7 +97,6 @@ function sprite(options) {
9797 this . render = function ( ) {
9898 // Sets the center of the element to where it's top left corner was
9999 // Then sets its center to the center of its parent
100- this . body . style . imageRendering = "pixelated"
101100 this . body . style . position = "absolute"
102101 this . body . style . left = ( this . pos . x - this . size . x / 2 ) + nopx ( this . parent . body . style . width ) / 2 + "px"
103102 this . body . style . top = ( - this . pos . y - this . size . y / 2 ) + nopx ( this . parent . body . style . height ) / 2 + "px"
@@ -120,11 +119,11 @@ function sprite(options) {
120119 this . body . style . background = "url(" + this . texture . src + ")"
121120 }
122121
123-
124122 this . body . style . transform += "translate(" + this . offset . x + "px, " + this . offset . y + "px) "
125123 this . body . style . transformOrigin = ( - this . offset . x + this . body . style . width / 2 ) + "px " + ( - this . offset . y + this . body . style . height / 2 ) + "px"
124+ this . body . style . imageRendering = "pixelated"
126125
127-
126+ //this.body.style.filter = "drop-shadow(5px 5px 5px #222)"
128127
129128 this . body . style . border = this . debug ? "1px solid yellow" : "none"
130129 }
@@ -139,7 +138,6 @@ window.onload = function() {
139138 x : 1000 ,
140139 y : 1000
141140 } ,
142- //scale: 1,
143141 offset : {
144142 x : 0 ,
145143 y : 0
@@ -148,7 +146,7 @@ window.onload = function() {
148146 x : 0 ,
149147 y : 0 ,
150148 z : 0 ,
151- p : 500
149+ p : 0
152150 } ,
153151 texture : "background.png"
154152 } )
@@ -171,32 +169,38 @@ window.onload = function() {
171169 canvas . style . width = window . innerWidth + "px"
172170 canvas . style . height = window . innerHeight + "px"
173171
174- let camZoom = 0
175- world . setScale ( 0.5 + ( camZoom + 1 ) * camZoom )
172+ let camZoom = 1
173+ world . setScale ( Math . pow ( camZoom + 1 , 2 ) )
176174 canvas . onwheel = function ( e ) {
177175 camZoom += e . deltaY / - 1000
178- camZoom = clamp ( camZoom , 0 , 3 )
176+ camZoom = clamp ( camZoom , - 0.29 , 3 )
179177 camZoom = Math . floor ( camZoom * 100 ) / 100 // Removes any imprecision errors
180- world . setScale ( 0.5 + ( camZoom + 1 ) * camZoom )
181- console . log ( world . scale )
178+ world . setScale ( Math . pow ( camZoom + 1 , 2 ) )
182179 }
183180
181+ const debugInfo = this . document . getElementById ( "debugInfo" )
182+
184183 const camPos = { x :0 , y :0 }
185184 function render ( ) {
186- const camSpeed = heldKeys [ "ShiftLeft" ] ? 24 : 12
187- if ( heldKeys [ "KeyW" ] ) { camPos . y -= camSpeed / world . scale }
188- if ( heldKeys [ "KeyS" ] ) { camPos . y += camSpeed / world . scale }
185+ let camSpeed = 12
186+ if ( heldKeys [ "ShiftLeft" ] ) { camSpeed *= 2 }
187+ if ( heldKeys [ "KeyW" ] ) { camPos . y += camSpeed / world . scale }
188+ if ( heldKeys [ "KeyS" ] ) { camPos . y -= camSpeed / world . scale }
189189 if ( heldKeys [ "KeyA" ] ) { camPos . x -= camSpeed / world . scale }
190190 if ( heldKeys [ "KeyD" ] ) { camPos . x += camSpeed / world . scale }
191191 camPos . x = clamp ( camPos . x , world . size . x / - 2 , world . size . x / 2 )
192192 camPos . y = clamp ( camPos . y , world . size . y / - 2 , world . size . y / 2 )
193193 world . setOffset ( {
194- x : world . offset . x + ( - world . offset . x - camPos . x ) / 10 ,
195- y : world . offset . y + ( - world . offset . y - camPos . y ) / 10
194+ x : world . offset . x + ( - world . offset . x - camPos . x ) / 5 , // range 0-20 +1
195+ y : world . offset . y + ( - world . offset . y + camPos . y ) / 5
196196 } )
197197 canvas . style . width = window . innerWidth + "px"
198198 canvas . style . height = window . innerHeight + "px"
199199 world . render ( )
200+
201+ debugInfo . innerText = ""
202+ debugInfo . innerText += "Cam X Y: " + camPos . x . toFixed ( 2 ) + " " + camPos . y . toFixed ( 2 ) + "\n"
203+ debugInfo . innerText += "Cam zoom: " + camZoom + " (" + world . scale . toFixed ( 2 ) + ")\n"
200204 }
201205
202206 setInterval ( render , 10 )
0 commit comments