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())
|
||||
//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
|
||||
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 +129,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user