Coder Social home page Coder Social logo

so-67453408's Introduction

Why is my Phaser3 sprite rendering in the wrong location?

This repo is a minimal reproducible example of bad rendering behavior of Phaser within Electron. It has been created to supplement this question on StackOverflow.

Note: I have only tested this on MacOS.

To run it

yarn && yarn start

After dependencies are installed and the app builds, a new application window will open. Within that window, you'll see:

  • the page has a white background
  • there is a black <canvas> rectangle in the top-left, with dimensions 400px by 200px; there is nothing else on the page
  • in the top-left corner of the <canvas>, you'll see a red square that's 100px on a side, with a 1px green border that's visible on all four sides of the square

What's wrong?

Open src/scene.js and look at line 23: the sprite is being placed at coordinates (200,100) even though it displays in the top-left corner.

To the best of my knowledge, the correct coordinates for that position should be (0,0).

Notably, (200,100) is half the canvas dimensions. If you increase the canvas size to e.g. 600px by 300px, to achieve the same position, you must place the sprite at (300,150), which is also not how it's supposed to work.

There's nothing else going on in this repo.

To make edits

Note that this repo does not do hot-reloading, because this is supposed to be a minimal example. If you want to see your changes, you must kill the Electron app and then re-run yarn start.

so-67453408's People

Contributors

tomprogers avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.