Skip to content

Commit

Permalink
refactor(events): optimize perf and move setCamPos from player to cur…
Browse files Browse the repository at this point in the history
…sors
  • Loading branch information
remarkablemark committed Jan 22, 2025
1 parent 0878b8f commit 0f00bee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/events/cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ export function addCursorKeys(player: Player) {
case 'left':
case 'a':
player.move(-SPEED, 0)
setCameraPosition(player)
break

case 'right':
case 'd':
player.move(SPEED, 0)
setCameraPosition(player)
break

case 'up':
case 'w':
player.move(0, -SPEED)
setCameraPosition(player)
break

case 'down':
case 's':
player.move(0, SPEED)
setCameraPosition(player)
break
}
})
}

function setCameraPosition(player: Player) {
setCamPos(player.worldPos()!)
}
4 changes: 0 additions & 4 deletions src/gameobjects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export function addPlayer(x = center().x, y = center().y) {
Tag.Player,
])

player.onUpdate(() => {
setCamPos(player.worldPos()!)
})

addCursorKeys(player)

const attack = new Attack(player)
Expand Down

0 comments on commit 0f00bee

Please sign in to comment.