Skip to content

Commit f3a87f2

Browse files
authored
Merge pull request #724 from JiepengTan/pr_fix_apply_custume_offset_2_animation
Add config to ApplyCustumeOffset2Animation
2 parents d06658b + fcc9217 commit f3a87f2

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

cmd/gox/template/project/.builds/web/runner.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@
8484
onGameError = callback
8585
}
8686

87-
window.startGame = async (buffer, assetURLs = null, onSpxReady = null) => {
87+
window.startGame = async (buffer, assetURLs = null, onSpxReady = null, logLevel = LOG_LEVEL_NONE) => {
8888
isShowEditor = false
8989
const config = {
9090
'projectName': "spx_game",
9191
'onProgress': onProgress,
9292
"gameCanvas": document.getElementById('game-canvas'),
9393
"editorCanvas": document.getElementById('editor-canvas'),
9494
"projectData": new Uint8Array(buffer),
95-
"logLevel": LOG_LEVEL_NONE,
95+
"logLevel": logLevel,
9696
"useAssetCache": false,
9797
"isRuntimeMode": true,
9898
"assetURLs": {

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ type spriteConfig struct {
275275
TriggerCenter mathf.Vec2 `json:"triggerCenter"`
276276
TriggerSize mathf.Vec2 `json:"triggerSize"`
277277
TriggerRadius float64 `json:"triggerRadius"`
278+
279+
ApplyCustumeOffset2Animation bool `json:"applyCustumeOffset2Animation"`
278280
}
279281

280282
func (p *spriteConfig) getCostumeIndex() int {

gdspx.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func applyRenderOffset(p *SpriteImpl, cx, cy *float64) {
317317
*cy = *cy + y
318318
}
319319

320-
func registerAnimToEngine(spriteName string, animName string, animCfg *aniConfig, costumes []*costume, isCostumeSet bool) {
320+
func registerAnimToEngine(spriteName string, animName string, animCfg *aniConfig, costumes []*costume, isCostumeSet bool, applyCustumeOffset2Animation bool) {
321321
// TODO(jiepengtan): here we should optimize the implementation, it's better to use json to map, avoid manually writing parsing code
322322
sb := strings.Builder{}
323323
from, to := animCfg.IFrameFrom, animCfg.IFrameTo
@@ -356,10 +356,14 @@ func registerAnimToEngine(spriteName string, animName string, animCfg *aniConfig
356356
if strings.Contains(assetPath, splitTag) {
357357
panic("assetPath is invalid, should not contains " + splitTag + " " + costumes[i].path)
358358
}
359-
costume := costumes[i]
360359
sb.WriteString(assetPath)
361-
halfSize := mathf.Vec2.Mulf(costume.imageSize, 0.5)
362-
sb.WriteString(splitTag + fmt.Sprintf("%f,%f", costume.center.X-halfSize.X, -costume.center.Y+halfSize.Y))
360+
if applyCustumeOffset2Animation {
361+
costume := costumes[i]
362+
halfSize := mathf.Vec2.Mulf(costume.imageSize, 0.5)
363+
sb.WriteString(splitTag + fmt.Sprintf("%f,%f", costume.center.X-halfSize.X, -costume.center.Y+halfSize.Y))
364+
} else {
365+
sb.WriteString(splitTag + fmt.Sprintf("%f,%f", 0.0, 0.0))
366+
}
363367
if i != to {
364368
sb.WriteString(";")
365369
}

sprite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (p *SpriteImpl) init(
330330

331331
// register animations to engine
332332
for animName, ani := range p.animations {
333-
registerAnimToEngine(p.name, animName, ani, p.baseObj.costumes, p.isCostumeSet)
333+
registerAnimToEngine(p.name, animName, ani, p.baseObj.costumes, p.isCostumeSet, spriteCfg.ApplyCustumeOffset2Animation)
334334
}
335335

336336
}

0 commit comments

Comments
 (0)