JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://pixijs.download/v4.8.9/pixi.js"></script>
<canvas id='game_canvas'>
</canvas>
<button id='move_btn'>move stage to right by 20px</button>
CSS
body {
margin: 0px;
}
#move_btn {
position: absolute;
top: 20px;
left: 20px;
}
JavaScript
const canvas = document.getElementById('game_canvas')
const TILE_SIZE = 32
const SHIP_SIZE = 8 * TILE_SIZE
const app = window.app = new PIXI.Application({
view: canvas,
forceCanvas: true,
antialias: true,
width: window.innerWidth,
height: window.innerHeight
})
app.renderer.view.style.position = "absolute"
app.renderer.view.style.display = "block"
// this.app.renderer.backgroundColor = 0x000a19
app.renderer.backgroundColor = 0x000000
app.stage.scale.y = 1
app.stage.scale.x = 1
const origContainer = new PIXI.Container()
app.stage.addChild(origContainer)
let style = {fontSize: 20, fontFamily: "Arial", align: "center", fill : 0xeeeeee, strokeThickness: 3 }
let text = new PIXI.Text("orig", style)
origContainer.addChild(text)
text.position.x = 45
text.position.y = 45
function createTileTexture(color) {
let graphics = new PIXI.Graphics()
graphics.beginFill(color)
graphics.drawRect(0, 0, TILE_SIZE, TILE_SIZE)
graphics.endFill()
return app.renderer.generateTexture(graphics)
}
function createBorderTexture(width, height) {
let graphics = new PIXI.Graphics()
graphics.lineStyle(1, 0x00ff00)
graphics.drawRect(0, 0, width, height)
return app.renderer.generateTexture(graphics)
}
function createTile(texture, row, col) {
let sprite = new PIXI.Sprite(texture)
sprite.position.set(col * TILE_SIZE, row * TILE_SIZE)
return sprite
}
let ship = new PIXI.Container()
ship.position.set(6 * TILE_SIZE, 6 * TILE_SIZE)
// uncomment this to fix the prob (avoids calling generateTexture)
let borderTexture = createBorderTexture(SHIP_SIZE, SHIP_SIZE)
origContainer.addChild(ship)
move_btn.addEventListener("click", function() {
app.stage.position.x += 20
}, true)