animated sprite
This commit is contained in:
parent
297e33d89e
commit
748f605bff
20
main.go
20
main.go
@ -96,6 +96,8 @@ func run() {
|
|||||||
var now int64
|
var now int64
|
||||||
var dt int64
|
var dt int64
|
||||||
|
|
||||||
|
frameCounter := 0
|
||||||
|
|
||||||
// Game Loop
|
// Game Loop
|
||||||
for !win.Closed() {
|
for !win.Closed() {
|
||||||
now = time.Now().UnixNano()
|
now = time.Now().UnixNano()
|
||||||
@ -126,23 +128,33 @@ func run() {
|
|||||||
|
|
||||||
//mouse := cam.Unproject(win.MousePosition())
|
//mouse := cam.Unproject(win.MousePosition())
|
||||||
|
|
||||||
|
frameCounter += 1
|
||||||
|
if frameCounter >= 3 {
|
||||||
|
frameCounter = 0
|
||||||
|
}
|
||||||
speed := 10.0
|
speed := 10.0
|
||||||
|
sprFrame := 0
|
||||||
if win.Pressed(pixelgl.KeyA) { //left
|
if win.Pressed(pixelgl.KeyA) { //left
|
||||||
|
sprFrame = 6
|
||||||
playerX -= speed
|
playerX -= speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[6])
|
//Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyD) { //Right
|
if win.Pressed(pixelgl.KeyD) { //Right
|
||||||
|
sprFrame = 3
|
||||||
playerX += speed
|
playerX += speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[3])
|
//Sprite.Set(spritesheet, spritesFrames[3])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyS) { //Down
|
if win.Pressed(pixelgl.KeyS) { //Down
|
||||||
|
sprFrame = 9
|
||||||
playerY -= speed
|
playerY -= speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[9])
|
//Sprite.Set(spritesheet, spritesFrames[9])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyW) { //up
|
if win.Pressed(pixelgl.KeyW) { //up
|
||||||
|
sprFrame = 0
|
||||||
playerY += speed
|
playerY += speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[0])
|
//Sprite.Set(spritesheet, spritesFrames[0])
|
||||||
}
|
}
|
||||||
|
Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter])
|
||||||
camPos.X = playerX
|
camPos.X = playerX
|
||||||
camPos.Y = playerY
|
camPos.Y = playerY
|
||||||
camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y)
|
camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user