I hope that by trying removals and changing parameters, you have figured out what these lines of code do:
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(frameWidth)/2, -float64(frameHeight)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
In case you haven’t, let’s quickly check the Cheatsheet for ebiten.DrawImageOptions
type DrawImageOptions struct {
// GeoM is a geometry matrix to draw.
// The default (zero) value is identify, which draws the image at (0, 0).
GeoM GeoM
// ColorM is a color matrix to draw.
// The default (zero) value is identity, which doesn't change any color.
ColorM ColorM
// CompositeMode is a composite mode to draw.
// The default (zero) value is regular alpha blending.
CompositeMode CompositeMode
// Filter is a type of texture filter.
// The default (zero) value is FilterDefault.
Filter Filter
}
And here is Cheatsheet for ebiten.GeoM
Last time, we stopped at mentioning that there are three functions needed for the game loop: Update()
, Draw()
and Layout()
, of which all are functions of the Game
struct. According to the cheatsheet, the whole Game
struct is an instance of the Game
interface, as follow:
type Game interface {
// Update updates a game by one tick. The given argument represents a screen image.
Update(screen *Image) error
// Draw draw the game screen. The given argument represents a screen image.
//
// (To be exact, Draw is not defined in this interface due to backward compatibility, but RunGame's
// behavior depends on the existence of Draw.)
Draw(screen *Image)
// Layout accepts a native outside size in device-independent pixels and returns the game's logical
// screen size. On desktops, the outside is a window or a monitor (fullscreen mode)
//
// Even though the outside size and the screen size differ, the rendering scale is automatically
// adjusted to fit with the outside.
//
// You can return a fixed screen size if you don't care, or you can also return a calculated screen
// size adjusted with the given outside size.
Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)
}
If you have a background of C, C++, Java and the like, concepts of interface (and struct) might be familiar to you, but in case they aren’t, here are my quick explanations:
This weekend I decided to start another tutorial series in this blog, as I did learn a lot during making the last one. This time I decided to up the ante by picking up on a language that I am not very familiar with: Go Programming Language, or Golang. If it is the first time you heard of it, Go is a language designed at Google, is syntactically similar to C and is very well-designed to support concurrency. One of Go’s authors, Ken Thompson, was also one author of B language (together with Dennis Ritchie) (B was the direct predecessor of C Programming Language).
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part tutorial. To see other posts in the same series, please click below:
This is one part of a multi-part post. To see other posts in the same series, please click below: Part 1 Part 2 Part 3
This is an important point: Programming is not about remembering all the little detail about your language of choice, nor it is about reading a lot of books or watching several tutorial videos. It is about mastering some tools so that you can make things you want to make.
This is one part of a multi-part post. To see other posts in the same series, please click below: Part 1 Part 2 Part 3
One of the things that everyone should know but have almost never been taught at school is the skill to acquire knowledge. Instead, we were taught how to pass the exams by cramming into our mind a bunch of cr*p that, most of the time, have no practical values. (Even now, whenever I think about my “lessons” in school, the thing that I remember most is how exhausted I was every time I had an exam.)
A buddy of mine from college just started learning programming in Python, and he told me that it was “very complicated” and there are too many things to remember, which he normally mix up. As someone who just started teaching himself to code a few years ago, I understand the feeling, and for that reason I would like to write this post to share some of my experience. Hopefully it will have the chance to help some of you guys out there, who, like my friend and I, want to learn programming but find it too challenging.