shepelevstas

Members
  • Content Count

    4
  • Joined

  • Last visited

About shepelevstas

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thank you! I wrote a class to handle height maps from png images! class HMap { constructor(img, offsetX = 0, offsetY = 0){ this._w = img.width this._h = img.height this._offsetX = offsetX this._offsetY = offsetY this._data = this._getData(img) } _getData(img){ const canvas = document.createElement('canvas') canvas.width = this._w canvas.height = this._h const context = canvas.getContext('2d', { alpha: false }) context.drawImage(img, 0, 0, this._w, this._h) return context.getImageData(0, 0, this._w, this._h).data } pixel(x, y){ if ( x < this._offsetX || x >= this._offsetX + this._w || y < this._offsetY || y >= this._offsetY + this._h ) return [this._data[0], this._data[1], this._data[2]] const i = (y - this._offsetY) * this._w * 4 + (x - this._offsetX) * 4 return [this._data[i], this._data[i+1], this._data[i+2]] } } And I get img from "PIXI.loader.resources['height_map.png'].data"! Is it ok? I could not find anything about "texture.baseTexture.source" or "texture.baseTexture.resource.source" in docs or source files.
  2. Hello! I want to use png image as a height map for an isometric pixel game. I don't need to display it. I only need to load it and read pixel values in form of [r,g,b,a]. There are libs like png.js, which has png.getPixel(x,y). But I believe PIXI already has all I need for that. How can I do it? Instance of what class should I use? Or is there a way to convert a png image to a typed array? Or may be all this is a bad idea?
  3. Thank you for rapid reply! I wouldn't expect it in such an outdated thread! After some experiments I figured out many of my questions: "position" in Container.toLocal(position... is a position in global coordinates! A global position. Not the root of world(or global) coordinates as I would parse "world origin to calculate from". The very important implicit piece of information about .toLocal is that it expects the "positioin" to be global! So when I try to calc doc.toLocal(bunny) (which is dumb even without understanding all that since bunny.parent is doc 😄 looks like yesterday my head stopped working after many hours of trying to make some sense out of it 😄, and when I drag the whole scene around, the result changes since global position of the doc changes! And I guess its' global position is accounted for when calculating some local position (local to the doc) of some global "position". So the equivalent for PIXI mouse event handler event.data.getLocalPosition(docContainer) in context of native mouse events would be docContainer.toLocal(globalMousePosition) where globalMousePosition is set with the help of app.renderer.plugins.interaction.mapPositionToPoint(globalMousePosition, event.x, event.y). Yes, maybe "relative to" is a better term . I sea what you mean talking about chess. I feel like I'm trying to study Go (strategy board game). The game has only 10 rules, but the strategy is so complex and hard to put in words that the entrance learning curve is very steep I hope this would be useful to someone like me yesterday struggling to understand and stumbling upon this thread in Google I would say that PIXI.Container.toLocal(position) converts a global position into local coordinates of the Container. And the IMPORTANT part is that it expects the "position" param to be in global coordinates! And I have no idea what PIXI.Container.toLocal(position, from) does 😆
  4. Could you help me with this? It's very difficult to grasp. The documentation terms and wording are confusing. I have a Sprite (named 'bunny') inside a Container (named 'doc') inside another Container ('doc and shadow' and it can be dragged around with spacebar held down) inside stage. Working on a graphics editor like a simple Photoshop. While dragging 'bunny' I was using .on('mouse... events. The handler function gets PIXI-event with its' event.data.getLocalPosition(). I used it, feeding 'doc' Container to it to calculate new 'bunny' position. But for the functionality I'm trying to implement I have to use native app.view.addEventListener('mousedown', event =>. And that native event does not have .data.getLocalPosition(), only event.x and event.y. I tried doc.toLocal(... and bunny.toLocal(... while reading documentation. Experimenting I tried logging doc.toLocal(bunny) and noticed that though while doc and bunny didn't move relative to each other, dragging the whole 'doc and shadow' Container around changed the result of doc.toLocal(bunny) method. Why?? The documentation says PIXI.Container.toLocal(position, from, point, skipUpdate), where position is "The world origin to calculate from." So does that mean that doc.toLocal(bunny) calculates the position of doc in terms of bunny coordinates (since it's "world origin")? But in previous post you wrote that it's the opposite. So 'bunny's position (which is "The world origin to calculate from.") is translated to doc's coordinates?? (which I was hoping would be the same as event.data.getLocalPosition(doc), but I failed) The documentation also says that PIXI.Container.toLocal "Calculates the local position of the display object relative to another point." Is "the display object" is the Container on which the method is called? Then again doc.toLocal(bunny) means doc local position in bunny coordinates? "another point" - is it "position" (the bunny in my case) or is it the "point" from .toLocal(position, from, point, skipUpdate)?? Could you please bring a little light to it?