Jump to content

Can I apply pixelArt + Round pixels to a sprite only?


Poe
 Share

Recommended Posts

I believe you can create an extra camera for your player in the scene, have the main camera ignore your player and the extra camera ignore everything but the player and then use the setRroundPixels method on the extra camera. 

You can see a similar effect with blurring one image and not the other in this example

 

EDIT: Quick example of the idea here without all the extra pipeline stuff.

Edited by GreenCloversGuy
Provided better example
Link to comment
Share on other sites

37 minutes ago, cornstipated said:

You can control roundpixels/antialiasing on a per texture basis by using sprite.texture.setFilter(filtermode)

Phaser.Textures.FilterMode.LINEAR or Phaser.Textures.FilterMode.Nearest

This did the trick - But goes back to being blurry on animations. ?

So I can either call it after every time I change an animation, or I could throw it in update to (feels a bit wasteful).

Not sure the best way to tackle this, is there a way I could run it every time play is ran on the object? 

Link to comment
Share on other sites

2 hours ago, Poe said:

This did the trick - But goes back to being blurry on animations. ?

So I can either call it after every time I change an animation, or I could throw it in update to (feels a bit wasteful).

Not sure the best way to tackle this, is there a way I could run it every time play is ran on the object? 

I haven't verified this so there is definitely an aspect of "left to the reader" that's not great but I don't have the time to do it right now. Possibly somebody else can help fill in the gaps if necessary...

If you look at an animation it's composed of a series of AnimationFrames. Those frames are just a a texture key + frame number (or name) (source). I believe when the animation manager updates the frame for a sprite it will result in .texture just being swapped to whichever texture is referenced by the texture key. When you switch between animations this should result in the same texture being used repeatedly (due to texture cache) and not a new texture being created every time.

I believe that means once you've set the texture's filter to LINEAR / Nearest you won't need to do it again. This should be reasonably simple to test in your code by only calling sprite.texture.setFilter the first time you switch to a given animation (and subsequent uses of that animation should still look good).

If that proves to be true then you should be able to just preemptively set the texture filter to LINEAR in your scene's create method (or any time after they're loaded). For example:

class TestScene extends Phaser.Scene {
  constructor() {
    super({key: 'testscene'})
  }

  preload() {
    // load whatever spritesheet you want to use for your animations
    this.load.spritesheet(
      'animations_ss',
      'http://example.com/spritesheet.png',
    )
  }

  create() {
    // now that the loading is known to be finished go into the texture manager
    // for this scene and pull the spritesheet out
    const animSheet = this.textures.get('animations_ss')

    // then set the filter style for that texture
    animSheet.setFilter(Phaser.Textures.FilterMode.LINEAR)
  }
}

Again, I'm not positive that this is going to work but there is a reasonable chance it will.

Good luck!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...