Merge branch 'setting-character-sprite' into 'experimental'
Setting character sprite See merge request zolfite/project-rpg!1
This commit is contained in:
commit
d06a0c85b3
26
main.go
26
main.go
@ -52,20 +52,22 @@ func run() {
|
|||||||
bg := pixel.NewSprite(background, background.Bounds())
|
bg := pixel.NewSprite(background, background.Bounds())
|
||||||
//batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
//batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
||||||
|
|
||||||
/*
|
|
||||||
When creating the sprite, you need to know big each frame is inside the spritesheet.
|
/* setting-character-sprite
|
||||||
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
|
basically changed it around so the 12 frames of the character with yellow hair
|
||||||
we increment it by 96 for both x and y so that it can get the position of the frame
|
are added to spritesFrames.
|
||||||
at the bottom right corner.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var spritesFrames []pixel.Rect
|
var spritesFrames []pixel.Rect
|
||||||
for x := spritesheet.Bounds().Min.X; x < spritesheet.Bounds().Max.X; x += 96 {
|
var frameWidth, frameHeight float64 = 96, 96
|
||||||
for y := spritesheet.Bounds().Min.Y; y < spritesheet.Bounds().Max.Y; y += 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
|
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 (
|
var (
|
||||||
camPos = pixel.ZV
|
camPos = pixel.ZV
|
||||||
@ -127,15 +129,15 @@ func run() {
|
|||||||
speed := 10.0
|
speed := 10.0
|
||||||
if win.Pressed(pixelgl.KeyA) { //left
|
if win.Pressed(pixelgl.KeyA) { //left
|
||||||
playerX -= speed
|
playerX -= speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[2])
|
Sprite.Set(spritesheet, spritesFrames[6])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyD) { //Right
|
if win.Pressed(pixelgl.KeyD) { //Right
|
||||||
playerX += speed
|
playerX += speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[1])
|
Sprite.Set(spritesheet, spritesFrames[3])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyS) { //Down
|
if win.Pressed(pixelgl.KeyS) { //Down
|
||||||
playerY -= speed
|
playerY -= speed
|
||||||
Sprite.Set(spritesheet, spritesFrames[3])
|
Sprite.Set(spritesheet, spritesFrames[9])
|
||||||
}
|
}
|
||||||
if win.Pressed(pixelgl.KeyW) { //up
|
if win.Pressed(pixelgl.KeyW) { //up
|
||||||
playerY += speed
|
playerY += speed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user