From 452bd9cdc346b09e1c64505b66316a4fc506a0c0 Mon Sep 17 00:00:00 2001 From: Jalen Winslow Date: Tue, 23 Jan 2018 05:38:52 -0700 Subject: [PATCH 1/2] added frames only concerning sprite --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 12e6cbb..73f4f64 100644 --- a/main.go +++ b/main.go @@ -60,12 +60,13 @@ func run() { at the bottom right corner. */ var spritesFrames []pixel.Rect - for x := spritesheet.Bounds().Min.X; x < spritesheet.Bounds().Max.X; x += 96 { - for y := spritesheet.Bounds().Min.Y; y < spritesheet.Bounds().Max.Y; y += 96 { + var frameWidth, frameHeight float64 = 96, 96 + for y := spritesheet.Bounds().Min.Y; y < frameHeight*4; y += 96 { + for x := spritesheet.Bounds().Min.X; x < frameWidth*3; x += 96 { spritesFrames = append(spritesFrames, pixel.R(x, y, x+96, y+96)) // (x, y, width, height) of frame } } - Sprite := pixel.NewSprite(spritesheet, spritesFrames[3]) + Sprite := pixel.NewSprite(spritesheet, spritesFrames[9]) var ( camPos = pixel.ZV @@ -127,15 +128,15 @@ func run() { speed := 10.0 if win.Pressed(pixelgl.KeyA) { //left playerX -= speed - Sprite.Set(spritesheet, spritesFrames[2]) + Sprite.Set(spritesheet, spritesFrames[6]) } if win.Pressed(pixelgl.KeyD) { //Right playerX += speed - Sprite.Set(spritesheet, spritesFrames[1]) + Sprite.Set(spritesheet, spritesFrames[3]) } if win.Pressed(pixelgl.KeyS) { //Down playerY -= speed - Sprite.Set(spritesheet, spritesFrames[3]) + Sprite.Set(spritesheet, spritesFrames[9]) } if win.Pressed(pixelgl.KeyW) { //up playerY += speed From 297e33d89ef2f6af2b529fb24e530297a8d2c24a Mon Sep 17 00:00:00 2001 From: Jalen Winslow Date: Tue, 23 Jan 2018 05:52:53 -0700 Subject: [PATCH 2/2] added frames only concerning sprite --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 73f4f64..1529f3b 100644 --- a/main.go +++ b/main.go @@ -52,13 +52,14 @@ func run() { bg := pixel.NewSprite(background, background.Bounds()) //batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet) - /* - When creating the sprite, you need to know big each frame is inside the spritesheet. - If you use aseprite or some other pixel art program, you can find the number of pixels - within each frame. For our sprite sheet, each frame is 96 px wide and 96 px high. So - we increment it by 96 for both x and y so that it can get the position of the frame - at the bottom right corner. + + /* setting-character-sprite + + basically changed it around so the 12 frames of the character with yellow hair + are added to spritesFrames. + */ + var spritesFrames []pixel.Rect var frameWidth, frameHeight float64 = 96, 96 for y := spritesheet.Bounds().Min.Y; y < frameHeight*4; y += 96 {