safex-webgl 1.0.2 → 1.0.3
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/package.json +11 -1
- package/test/ActionScene.ts +0 -15
- package/test/DemoScene.ts +0 -108
- package/test/GraphicsTest.ts +0 -24
- package/test/ParticleScene.ts +0 -47
- package/test/TiledMapScene.ts +0 -19
- package/test/index.ts +0 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safex-webgl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
"types": "./dist/*/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cocos",
|
|
16
|
+
"safex",
|
|
17
|
+
"safe-engine",
|
|
18
|
+
"game",
|
|
19
|
+
"2d"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"url": "https://github.com/Safe-engine/safex-webgl"
|
|
23
|
+
},
|
|
14
24
|
"scripts": {
|
|
15
25
|
"dev": "vite",
|
|
16
26
|
"compile": "tsc",
|
package/test/ActionScene.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { view } from '../src'
|
|
2
|
-
import { moveBy } from '../src/actions'
|
|
3
|
-
import { Scene, Sprite } from '../src/core'
|
|
4
|
-
import { p } from '../src/core/cocoa/Geometry'
|
|
5
|
-
|
|
6
|
-
export class ActionScene extends Scene {
|
|
7
|
-
onEnter() {
|
|
8
|
-
super.onEnter()
|
|
9
|
-
const sprite = new Sprite('button_plus.png')
|
|
10
|
-
sprite.setPosition(view.getDesignResolutionSize().width / 2, view.getDesignResolutionSize().height / 2)
|
|
11
|
-
this.addChild(sprite)
|
|
12
|
-
const moveAction = moveBy(5, p(100, 600))
|
|
13
|
-
sprite.runAction(moveAction)
|
|
14
|
-
}
|
|
15
|
-
}
|
package/test/DemoScene.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClippingNode,
|
|
3
|
-
Color,
|
|
4
|
-
FontDefinition,
|
|
5
|
-
LabelTTF,
|
|
6
|
-
Rect,
|
|
7
|
-
Scene,
|
|
8
|
-
Sprite,
|
|
9
|
-
Vec2,
|
|
10
|
-
audioEngine,
|
|
11
|
-
director,
|
|
12
|
-
loader,
|
|
13
|
-
spriteFrameCache,
|
|
14
|
-
view,
|
|
15
|
-
} from '../src'
|
|
16
|
-
import { MotionStreak } from '../src/motion-streak'
|
|
17
|
-
import { ProgressTimer } from '../src/progress-timer'
|
|
18
|
-
import { Button, RichElementText, RichText, Scale9Sprite, Slider, Text } from '../src/ui'
|
|
19
|
-
|
|
20
|
-
export class DemoScene extends Scene {
|
|
21
|
-
declare streak: MotionStreak
|
|
22
|
-
constructor() {
|
|
23
|
-
super()
|
|
24
|
-
console.log('BootScene constructor')
|
|
25
|
-
const motionStreak = new MotionStreak(1, 32, 13, Color.GREEN, 'particle.png')
|
|
26
|
-
motionStreak.setPosition(300, 400)
|
|
27
|
-
this.addChild(motionStreak)
|
|
28
|
-
this.streak = motionStreak
|
|
29
|
-
this.scheduleUpdate()
|
|
30
|
-
}
|
|
31
|
-
onEnter() {
|
|
32
|
-
super.onEnter()
|
|
33
|
-
loader.load(['button.png', 'sliderThumb.png', 'ui.plist', 'ui.png'], (err: any, resources: any) => {
|
|
34
|
-
if (err) {
|
|
35
|
-
console.error('Failed to load image', err)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
console.log('Resources loaded', resources)
|
|
39
|
-
spriteFrameCache.addSpriteFrames('ui.plist', 'ui.png')
|
|
40
|
-
const sprite9 = new Scale9Sprite('button.png', Rect(10, 10, 20, 20))
|
|
41
|
-
sprite9.setContentSize(200, 234)
|
|
42
|
-
sprite9.setPosition(300, 900)
|
|
43
|
-
this.addChild(sprite9)
|
|
44
|
-
const sprite = new Sprite('button.png')
|
|
45
|
-
const sprite2 = new Sprite('button_plus.png')
|
|
46
|
-
const frame = spriteFrameCache.getSpriteFrame('ui/buttons/back')
|
|
47
|
-
const sprite3 = new Sprite(frame)
|
|
48
|
-
sprite2.setPosition(85, 226)
|
|
49
|
-
sprite3.setPosition(100, 200)
|
|
50
|
-
this.addChild(sprite3)
|
|
51
|
-
const mask = new ClippingNode(sprite3)
|
|
52
|
-
sprite2.setPosition(85, 226)
|
|
53
|
-
mask.setPosition(100, 200)
|
|
54
|
-
this.addChild(mask)
|
|
55
|
-
const timer = new ProgressTimer(sprite)
|
|
56
|
-
this.addChild(timer)
|
|
57
|
-
timer.setPercentage(60)
|
|
58
|
-
timer.setPosition(view.getDesignResolutionSize().width / 2, view.getDesignResolutionSize().height / 2)
|
|
59
|
-
timer.addChild(sprite2)
|
|
60
|
-
// console.log('sprite onEnter', timer)
|
|
61
|
-
timer.setType(ProgressTimer.TYPE_BAR)
|
|
62
|
-
timer.setMidpoint(Vec2(0, 0))
|
|
63
|
-
timer.setBarChangeRate(Vec2(1, 0))
|
|
64
|
-
const label = new LabelTTF('Hello World', 'Arial', 24)
|
|
65
|
-
label.setPosition(300, 200)
|
|
66
|
-
this.addChild(label)
|
|
67
|
-
const text = new Text('From Têxt', 'Arial', 24)
|
|
68
|
-
text.setPosition(500, 200)
|
|
69
|
-
this.addChild(text)
|
|
70
|
-
const rt = new RichText()
|
|
71
|
-
const fontDefinition = new FontDefinition()
|
|
72
|
-
fontDefinition.strokeEnabled = true
|
|
73
|
-
fontDefinition.strokeStyle = Color.GREEN
|
|
74
|
-
fontDefinition.lineWidth = 3
|
|
75
|
-
fontDefinition.fontName = 'Arial'
|
|
76
|
-
fontDefinition.fontSize = 48
|
|
77
|
-
const rtet = new RichElementText(1, fontDefinition, 255, 'rick text')
|
|
78
|
-
rt.pushBackElement(rtet)
|
|
79
|
-
rt.setPosition(200, 300)
|
|
80
|
-
this.addChild(rt)
|
|
81
|
-
const button = new Button('button.png')
|
|
82
|
-
button.setPosition(400, 300)
|
|
83
|
-
button.setTitleText('Click Me')
|
|
84
|
-
this.addChild(button)
|
|
85
|
-
button.addClickEventListener(() => {
|
|
86
|
-
console.log('Button clicked')
|
|
87
|
-
audioEngine.playEffect('Button.mp3', false)
|
|
88
|
-
})
|
|
89
|
-
const slider = new Slider('sliderTrack.png', 'sliderThumb.png')
|
|
90
|
-
slider.setPosition(400, 400)
|
|
91
|
-
this.addChild(slider)
|
|
92
|
-
// slider.loadSlidBallTextureNormal('sliderThumb.png')
|
|
93
|
-
slider.addEventListener((sender: Slider, type: number) => {
|
|
94
|
-
const percent = sender.getPercent()
|
|
95
|
-
console.log('Slider value changed', percent, type)
|
|
96
|
-
}, this)
|
|
97
|
-
console.log('Slider', slider)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
update(dt: number) {
|
|
102
|
-
// console.log('BootScene update', dt)
|
|
103
|
-
this.streak.setPositionY(this.streak.getPositionY() + dt * 500)
|
|
104
|
-
if (this.streak.getPositionY() > director.getWinSize().height) {
|
|
105
|
-
this.streak.setPositionY(0)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
package/test/GraphicsTest.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { DrawNode, Vec2 } from '../src'
|
|
2
|
-
import { color, Color, Scene, Sprite } from '../src/core'
|
|
3
|
-
export class GraphicsTest extends Scene {
|
|
4
|
-
onEnter() {
|
|
5
|
-
super.onEnter()
|
|
6
|
-
this.createSpriteSafe()
|
|
7
|
-
const draw = new DrawNode()
|
|
8
|
-
this.addChild(draw, 1)
|
|
9
|
-
const draw2 = new DrawNode()
|
|
10
|
-
this.addChild(draw2)
|
|
11
|
-
draw.drawRect(Vec2(100, 300), Vec2(200, 500), Color.RED, 0)
|
|
12
|
-
draw.drawDot(Vec2(300, 1500), 50)
|
|
13
|
-
const points: Vec2[] = [Vec2(40, 1040), Vec2(540, 640), Vec2(840, 940), Vec2(740, 1040)]
|
|
14
|
-
draw2.drawPoly(points, Color.BLUE, 20, Color.ORANGE)
|
|
15
|
-
draw2.drawRect(Vec2(600, 110), Vec2(350, 245), Color.MAGENTA, 5, Color.WHITE)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
createSpriteSafe() {
|
|
19
|
-
const sprite = new Sprite('button_plus.png')
|
|
20
|
-
sprite.setColor(color(255, 0, 0))
|
|
21
|
-
sprite.setPosition(300, 400)
|
|
22
|
-
this.addChild(sprite, 10)
|
|
23
|
-
}
|
|
24
|
-
}
|
package/test/ParticleScene.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { director, loader, textureCache } from '../src'
|
|
2
|
-
import { Scene, Sprite } from '../src/core'
|
|
3
|
-
import { decodeGzipBase64 } from '../src/helper/ZipUtils'
|
|
4
|
-
import { ParticleFireworks } from '../src/particle/examples'
|
|
5
|
-
import { ParticleSystem } from '../src/particle/ParticleSystem'
|
|
6
|
-
import { PNGReader } from '../src/particle/PNGReader'
|
|
7
|
-
|
|
8
|
-
const base64String =
|
|
9
|
-
'H4sIAAAAAAAAAwFmA5n8iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADLUlEQVRYCcXX51JbQRCEUeOc/f6v6ZzxHKFPLAoI84epmrp7985294QVxcXl5eWjh7Sn9yB/MWcej19sXQb87/iP8f+yiztWAOmzcYL5k/F9AX9m7/fWf83zTmLOVeD5AHECWieiKpR95D8nlhPcepbH7TYBL+dI/mrWRCRkrQIBZY9Q5vzb+PdxQj2P2ikBCPnrxb0TRMQpAYiRIa9lVcregR0TgATZm/G3W7cmxn5VaA6qQNkjEkNAMbPcDOpBJfYF6DMByJC/H3+3XSfC97IziATov8FD8HUcDmzZs+bETSF0Z+cEICeCE0TYOQFlHznSZoTQkwIc5PW+FqwC7NUGVagCXTvlXzNHXnXE5LsrulYAYFduX4Ts11b4LlaWlbXBWzNH2GxojzN4jgogJgENYreganyYGELsq1YCAOp9CZX5eivEwy9mltcvPvqwirBHSGKIQE6Eitg35forO5mxSo5cDJyVHIf3TRVSIxNgiUgIUO5Abel2qII4hLJnSk5M7XC2rMPGU5s2APO++11PiKBVUECEyAq5athHyvS6TO2vhOHB72/ILK+VtHnb0+EEAkeiLZGV2UpyG94cvRbgh+KcGyzenZb5l3FPbbBfzDks3zcmE9aBCIBF1FCt16meO98M6L3BEpeohIUHP65ZXvXJM2IH8oCAATZYiJWc+a7swJF/HvddnHjnuLgwE4RvY1XAAVMuwAHvHPA61cUDNnD6DUws8k/j2kJEZ8NahdjbWIBeVvJIgSISh4yJ8931SgBwpMhVwtPZKiIeaSJmeWWrgMolENh6pSKXrTjftcKU66m9ziViFSI+AWJ3tgoQADTwrtdKLvvinE2AfcAylTXyj9tn1UiE8ztbBdhUIiD2u9ez3PS5LP0QJe6UgKpgJhpOuPBv2DEBMubAmbI3H0BqDYEJcBOAy06mqpCI/xIw5zYViFx/gZc98IZyX0DtITIR+4M4n27afgX6CgB52dffsq9FawWqkipUCWLyWR7aKQEiHVwFuHbrX7batApNRO3wPOj77O3swf8zuquAneJZaEPZ14KqcOOKrYdOre8j4BTWvfZl8qD2D7ghcomuE8XXAAAAAElFTkSuQmCCksg8PmYDAAA='
|
|
10
|
-
|
|
11
|
-
export class ParticleScene extends Scene {
|
|
12
|
-
onEnter() {
|
|
13
|
-
super.onEnter()
|
|
14
|
-
const { width, height } = director.getWinSize()
|
|
15
|
-
loader.load(['Spiral.plist', 'SmallSun.plist', 'base.png', 'particle.png'], (err: any, resources: any) => {
|
|
16
|
-
console.log(resources)
|
|
17
|
-
const emitter = new ParticleSystem('Spiral.plist')
|
|
18
|
-
emitter.setPosition(width / 2, height / 3)
|
|
19
|
-
this.addChild(emitter)
|
|
20
|
-
const sun = new ParticleSystem('SmallSun.plist')
|
|
21
|
-
sun.setPosition(width / 2, height * 0.8)
|
|
22
|
-
this.addChild(sun)
|
|
23
|
-
const firework = new ParticleFireworks()
|
|
24
|
-
firework.setPosition(width / 3, height / 2)
|
|
25
|
-
const texture = textureCache.getTextureForKey('particle.png')!
|
|
26
|
-
firework.setTexture(texture)
|
|
27
|
-
this.addChild(firework)
|
|
28
|
-
|
|
29
|
-
const buffer = decodeGzipBase64(base64String)
|
|
30
|
-
const imgPath = 'base64png'
|
|
31
|
-
const canvasObj = document.createElement('canvas')
|
|
32
|
-
const myPngObj = new PNGReader(buffer)
|
|
33
|
-
myPngObj.render(canvasObj)
|
|
34
|
-
textureCache.cacheImage(imgPath, canvasObj)
|
|
35
|
-
|
|
36
|
-
const tex = textureCache.getTextureForKey(imgPath)!
|
|
37
|
-
// console.log(tex)
|
|
38
|
-
const sprite = new Sprite(tex)
|
|
39
|
-
sprite.setPosition(300, 300)
|
|
40
|
-
this.addChild(sprite)
|
|
41
|
-
// firework.setTexture(tex)
|
|
42
|
-
// sun.setTexture(texture)
|
|
43
|
-
// firework.setBlendFunc(770, 1)
|
|
44
|
-
console.log(firework)
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
}
|
package/test/TiledMapScene.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { loader, view } from '../src'
|
|
2
|
-
import { Rect, Scene } from '../src/core'
|
|
3
|
-
import { TMXTiledMap } from '../src/tilemap'
|
|
4
|
-
|
|
5
|
-
export class TiledMapScene extends Scene {
|
|
6
|
-
onEnter() {
|
|
7
|
-
super.onEnter()
|
|
8
|
-
loader.load(['orthogonal-test1.tmx', 'ortho-test1.png'], (err: any, resources: any) => {
|
|
9
|
-
const map = new TMXTiledMap('orthogonal-test1.tmx')
|
|
10
|
-
map.setPosition(12, view.getDesignResolutionSize().height / 2)
|
|
11
|
-
const layer = map.getLayer('map')!
|
|
12
|
-
const tile = layer.getTileAt(0, 11)
|
|
13
|
-
tile?.setPositionY(-100)
|
|
14
|
-
tile?.setTextureRect(Rect(0, 0, 101, 171))
|
|
15
|
-
console.log(tile)
|
|
16
|
-
this.addChild(map)
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
}
|
package/test/index.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { director, game, global, sys, view } from '../src'
|
|
2
|
-
import { ResolutionPolicy } from '../src/core'
|
|
3
|
-
import { TiledMapScene } from './TiledMapScene'
|
|
4
|
-
|
|
5
|
-
global._isContextMenuEnable = true
|
|
6
|
-
game.run(
|
|
7
|
-
{
|
|
8
|
-
debugMode: 1,
|
|
9
|
-
showFPS: true,
|
|
10
|
-
frameRate: 60,
|
|
11
|
-
id: 'gameCanvas',
|
|
12
|
-
renderMode: 2,
|
|
13
|
-
},
|
|
14
|
-
function onStart() {
|
|
15
|
-
// Pass true to enable retina display, disabled by default to improve performance
|
|
16
|
-
view.enableRetina(sys.os === sys.OS_IOS)
|
|
17
|
-
// Adjust viewport meta
|
|
18
|
-
view.adjustViewPort(true)
|
|
19
|
-
// Setup the resolution policy and design resolution size
|
|
20
|
-
const width = 720
|
|
21
|
-
const height = 1280
|
|
22
|
-
const policy = width > height ? ResolutionPolicy.FIXED_HEIGHT : ResolutionPolicy.FIXED_WIDTH
|
|
23
|
-
view.setDesignResolutionSize(width, height, policy)
|
|
24
|
-
// The game will be resized when browser size change
|
|
25
|
-
view.resizeWithBrowserSize(true)
|
|
26
|
-
director.runScene(new TiledMapScene())
|
|
27
|
-
},
|
|
28
|
-
)
|