@footgun/cobalt 0.6.13 → 0.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/bundle.js +10 -1
- package/examples/03-tiles/index.html +61 -4
- package/package.json +1 -1
- package/src/sprite/spritesheet.js +2 -2
- package/src/tile/tile.js +6 -0
package/CHANGELOG.md
CHANGED
package/bundle.js
CHANGED
|
@@ -8310,6 +8310,8 @@ async function init4(cobalt, nodeData) {
|
|
|
8310
8310
|
};
|
|
8311
8311
|
}
|
|
8312
8312
|
function draw4(cobalt, nodeData, commandEncoder) {
|
|
8313
|
+
if (!nodeData.data.material.texture)
|
|
8314
|
+
return;
|
|
8313
8315
|
const { device } = cobalt;
|
|
8314
8316
|
const loadOp = nodeData.options.loadOp || "load";
|
|
8315
8317
|
const renderpass = commandEncoder.beginRenderPass({
|
|
@@ -13058,6 +13060,13 @@ function perpendicularComponent(inp) {
|
|
|
13058
13060
|
return [-inp[1], inp[0]];
|
|
13059
13061
|
}
|
|
13060
13062
|
|
|
13063
|
+
// node_modules/round-half-up-symmetric/index.js
|
|
13064
|
+
function round(value) {
|
|
13065
|
+
if (value >= 0)
|
|
13066
|
+
return Math.round(value);
|
|
13067
|
+
return value % 0.5 === 0 ? Math.floor(value) : Math.round(value);
|
|
13068
|
+
}
|
|
13069
|
+
|
|
13061
13070
|
// src/primitives/primitives.js
|
|
13062
13071
|
var _tmpVec32 = vec3.create(0, 0, 0);
|
|
13063
13072
|
var primitives_default2 = {
|
|
@@ -14589,7 +14598,7 @@ function _writeSpriteBuffer(cobalt, node) {
|
|
|
14589
14598
|
const GAME_WIDTH = viewport.width / viewport.zoom;
|
|
14590
14599
|
const GAME_HEIGHT = viewport.height / viewport.zoom;
|
|
14591
14600
|
const projection = mat4.ortho(0, GAME_WIDTH, GAME_HEIGHT, 0, -10, 10);
|
|
14592
|
-
vec3.set(-viewport.position[0], -viewport.position[1], 0, _tmpVec33);
|
|
14601
|
+
vec3.set(-round(viewport.position[0]), -round(viewport.position[1]), 0, _tmpVec33);
|
|
14593
14602
|
const view = mat4.translation(_tmpVec33);
|
|
14594
14603
|
device.queue.writeBuffer(node.data.uniformBuffer, 0, view.buffer);
|
|
14595
14604
|
device.queue.writeBuffer(node.data.uniformBuffer, 64, projection.buffer);
|
|
@@ -51,6 +51,14 @@
|
|
|
51
51
|
display: none;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
button {
|
|
55
|
+
position: fixed;
|
|
56
|
+
left: 20px;
|
|
57
|
+
top: 20px;
|
|
58
|
+
user-select: none;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
</style>
|
|
55
63
|
</head>
|
|
56
64
|
<body>
|
|
@@ -59,6 +67,10 @@
|
|
|
59
67
|
<canvas id="viewport" width="480" height="270"></canvas>
|
|
60
68
|
</div>
|
|
61
69
|
|
|
70
|
+
<button type="button">disable fg sprite texture</button>
|
|
71
|
+
<button type="button" style="left: 180px">disable bg sprite texture</button>
|
|
72
|
+
|
|
73
|
+
|
|
62
74
|
<script type="module">
|
|
63
75
|
import Game from './Game.js'
|
|
64
76
|
import * as Cobalt from '../../bundle.js'
|
|
@@ -167,8 +179,23 @@ async function main () {
|
|
|
167
179
|
}
|
|
168
180
|
})
|
|
169
181
|
|
|
182
|
+
const tileNodeBG = await Cobalt.initNode(Game.renderer, {
|
|
183
|
+
type: 'cobalt:tile',
|
|
184
|
+
refs: {
|
|
185
|
+
// key is the var name defined in this node
|
|
186
|
+
// value is the var name in the cobalt resources dictionary
|
|
187
|
+
tileAtlas: tileAtlasNode,
|
|
188
|
+
hdr: hdrTex,
|
|
189
|
+
},
|
|
190
|
+
options: {
|
|
191
|
+
textureUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/Wj6HMwAAAAASUVORK5CYII=',
|
|
192
|
+
scrollScale: 1.0,
|
|
193
|
+
loadOp: 'clear',
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
|
|
170
197
|
// instantiate all runnable nodes
|
|
171
|
-
const
|
|
198
|
+
const tileNodeBg = await Cobalt.initNode(Game.renderer, {
|
|
172
199
|
type: 'cobalt:tile',
|
|
173
200
|
refs: {
|
|
174
201
|
// key is the var name defined in this node
|
|
@@ -179,11 +206,10 @@ async function main () {
|
|
|
179
206
|
options: {
|
|
180
207
|
textureUrl: 'assets/spelunky1.png',
|
|
181
208
|
scrollScale: 0.6,
|
|
182
|
-
//zIndex: 0,
|
|
183
209
|
}
|
|
184
210
|
})
|
|
185
211
|
|
|
186
|
-
const
|
|
212
|
+
const tileNodeFg = await Cobalt.initNode(Game.renderer, {
|
|
187
213
|
type: 'cobalt:tile',
|
|
188
214
|
refs: {
|
|
189
215
|
// key is the var name defined in this node
|
|
@@ -194,7 +220,6 @@ async function main () {
|
|
|
194
220
|
options: {
|
|
195
221
|
textureUrl: 'assets/spelunky0.png',
|
|
196
222
|
scrollScale: 1.0,
|
|
197
|
-
//zIndex: 5,
|
|
198
223
|
}
|
|
199
224
|
})
|
|
200
225
|
|
|
@@ -230,6 +255,38 @@ async function main () {
|
|
|
230
255
|
|
|
231
256
|
window.addEventListener('resize', debouncedResize, { passive: true })
|
|
232
257
|
|
|
258
|
+
const [ button, button2 ] = document.querySelectorAll('button')
|
|
259
|
+
button.addEventListener('click', function (ev) {
|
|
260
|
+
let textureUrl = ''
|
|
261
|
+
if (ev.target.textContent === 'disable fg sprite texture') {
|
|
262
|
+
|
|
263
|
+
tileNodeFg.enabled = false
|
|
264
|
+
|
|
265
|
+
// 1x1 pixel with rg channels set to 255 to indicate discard
|
|
266
|
+
// this effectively clears the tilemap.
|
|
267
|
+
//tileNodeFg.setTexture('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/')
|
|
268
|
+
ev.target.textContent = 'enable fg sprite texture'
|
|
269
|
+
} else {
|
|
270
|
+
tileNodeFg.enabled = true
|
|
271
|
+
//tileNodeFg.setTexture('assets/spelunky0.png')
|
|
272
|
+
ev.target.textContent = 'disable fg sprite texture'
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
button2.addEventListener('click', function (ev) {
|
|
277
|
+
let textureUrl = ''
|
|
278
|
+
if (ev.target.textContent === 'disable bg sprite texture') {
|
|
279
|
+
tileNodeBg.enabled = false
|
|
280
|
+
// 1x1 pixel with rg channels set to 255 to indicate discard
|
|
281
|
+
// this effectively clears the tilemap.
|
|
282
|
+
//tileNodeBg.setTexture('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/')
|
|
283
|
+
ev.target.textContent = 'enable bg sprite texture'
|
|
284
|
+
} else {
|
|
285
|
+
tileNodeBg.enabled = true
|
|
286
|
+
//tileNode.setTexture('assets/spelunky1.png')
|
|
287
|
+
ev.target.textContent = 'disable bg sprite texture'
|
|
288
|
+
}
|
|
289
|
+
})
|
|
233
290
|
|
|
234
291
|
|
|
235
292
|
const world = ECS.createWorld()
|
package/package.json
CHANGED
|
@@ -205,8 +205,8 @@ function _writeSpriteBuffer (cobalt, node) {
|
|
|
205
205
|
// cobalt.setViewportPosition(...)
|
|
206
206
|
//
|
|
207
207
|
// set 3d camera position
|
|
208
|
-
|
|
209
|
-
vec3.set(-viewport.position[0], -viewport.position[1], 0, _tmpVec3)
|
|
208
|
+
vec3.set(-round(viewport.position[0]), -round(viewport.position[1]), 0, _tmpVec3)
|
|
209
|
+
//vec3.set(-viewport.position[0], -viewport.position[1], 0, _tmpVec3)
|
|
210
210
|
const view = mat4.translation(_tmpVec3)
|
|
211
211
|
|
|
212
212
|
device.queue.writeBuffer(node.data.uniformBuffer, 0, view.buffer)
|
package/src/tile/tile.js
CHANGED
|
@@ -47,6 +47,7 @@ export default {
|
|
|
47
47
|
|
|
48
48
|
// optional
|
|
49
49
|
customFunctions: {
|
|
50
|
+
|
|
50
51
|
setTexture: async function (cobalt, node, texture) {
|
|
51
52
|
const { canvas, device } = cobalt
|
|
52
53
|
|
|
@@ -156,6 +157,11 @@ async function init (cobalt, nodeData) {
|
|
|
156
157
|
|
|
157
158
|
function draw (cobalt, nodeData, commandEncoder) {
|
|
158
159
|
|
|
160
|
+
// calling setTexture can cause the texture to be destroyed followed by this draw command
|
|
161
|
+
// so check for the undefined texture first and bail for a frame.
|
|
162
|
+
if (!nodeData.data.material.texture)
|
|
163
|
+
return
|
|
164
|
+
|
|
159
165
|
const { device } = cobalt
|
|
160
166
|
|
|
161
167
|
// on the first render, we should clear the color attachment.
|