@nerolang/game
v1.1.0
Published
```shell pnpm add @nerolang/game ``` ## How to use? ```js import { Game, GraphicsDeviceManager, Vector2 } from '@nerolang/game' import { Keyboard, Keys } from '@nerolang/input' import { Color, SpriteBatch, Texture2D } from '@nerolang/game/graphics'
Readme
@nerolang/game
Install
pnpm add @nerolang/gameHow to use?
import { Game, GraphicsDeviceManager, Vector2 } from '@nerolang/game'
import { Keyboard, Keys } from '@nerolang/input'
import { Color, SpriteBatch, Texture2D } from '@nerolang/game/graphics'
import { ContentManager } from '@nerolang/game/content'
class Game1 extends Game {
graphics;
spriteBatch;
content;
texture;
position;
constructor() {
super()
this.graphics = new GraphicsDeviceManager(this)
this.content = new ContentManager()
}
loadGraphicsContent() {
this.spriteBatch = new SpriteBatch(this.graphics.graphicsDevice)
this.texture = this.content.load('example.jpg')
this.position = Vector2.Zero
}
update(gameTime) {
const keyboardState = Keyboard.getState()
const offset = gameTime.elapsedGameTime
if (keyboardState.isKeyDown(Keys.W)) {
this.position.y -= offset
}
if (keyboardState.isKeyDown(Keys.A)) {
this.position.x -= offset
}
if (keyboardState.isKeyDown(Keys.S)) {
this.position.y += offset
}
if (keyboardState.isKeyDown(Keys.D)) {
this.position.x += offset
}
}
draw(gameTime) {
this.graphics.graphicsDevice.clear(Color.CornflowerBlue)
this.spriteBatch.begin()
this.spriteBatch.draw(this.texture, this.position, null, Color.White)
this.spriteBatch.end()
}
}
const game = new Game1()
game.run()