Jump to content

WRAP_ADDRESSMODE with Sprite2D


Recommended Posts

There is a question on using Sprite2D primitive when sprite size is larger then texture size.

The common usage scenario is filling some area with "pattern" texture. Logically, that behaviour can be achieved by setting wrapU and wrapV properties of underlying texture to Texture.WRAP_ADDRESSMODE. But Sprite2D doesn't support that usage scenario. In Sprite2D constructor:

super(settings);

this.texture = texture;
this.texture.wrapU = Texture.CLAMP_ADDRESSMODE;
this.texture.wrapV = Texture.CLAMP_ADDRESSMODE;

so, Sprite2D overrides texture settings.

That snippet will use CLAMP_ADDRESSMODE, ignoring texture settings.

tx.wrapU = Texture.WRAP_ADDRESSMODE;
tx.wrapV = Texture.WRAP_ADDRESSMODE;
let sprite = new Sprite2D(tx, ...);

But if you really want to have WRAP_ADDRESSMODE, you can do as following:

let sprite = new Sprite2D(tx, ...);
sprite.texture.wrapU = Texture.WRAP_ADDRESSMODE;
sprite.texture.wrapV = Texture.WRAP_ADDRESSMODE;

And the sprite will be filled with texture.

The workaround is fairy simple, but I want to know the logic behind that solution - texture settings override in constructor.

@Nockawa

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...