Sign in to follow this  
Jambutters

PIXI Texture frames

Recommended Posts

let loaderSource = PIXI.loader.resources;

let initPlayer = ():void =>{

    let croped = PIXI.loader.resources["./img/player.png"].texture;
    
    let t32Rect = new PIXI.Rectangle(0, 0, 32, 32);
    
   // console.log(croped);
    croped.frame = t32Rect;
    

    let player = new PIXI.Sprite(loaderSource["./img/player.png"].texture); //this is not displaying the entire image, rather it's using the .frame clip. Shouldn't this be the independent whole image/texture? 
    rootStage.addChild(player);
    
    console.log(player);
};

Not sure why the Sprite displayed on PIXI is a cropped image rather than the whole thing. Shouldn't it be the entire thing ? 

Share this post


Link to post
Share on other sites

Texture is a (baseTexture, frame). Sprite doesn't have frame. So you have to copy the texture, to achieve the thing you want.

Texture in resources is a (baseTexture, (0,0,baseTexture.width, baseTexture.height)). You modified it and put in sprite - you got the result ;)

```
let newTex = new PIXI.Texture(PIXI.loader.resources['lala'].texture, t32Rect);
//same as
let newTex = new PIXI.Texture(PIXI.loader.resources['lala'].texture.baseTexture, t32Rect);

let sprite = new PIXI.Sprite(newTex);
```

 

Share this post


Link to post
Share on other sites
4 hours ago, ivan.popelyshev said:

Texture is a (baseTexture, frame). Sprite doesn't have frame. So you have to copy the texture, to achieve the thing you want.

Texture in resources is a (baseTexture, (0,0,baseTexture.width, baseTexture.height)). You modified it and put in sprite - you got the result ;)


```
let newTex = new PIXI.Texture(PIXI.loader.resources['lala'].texture, t32Rect);
//same as
let newTex = new PIXI.Texture(PIXI.loader.resources['lala'].texture.baseTexture, t32Rect);

let sprite = new PIXI.Sprite(newTex);
```

 

OOHHH. I see. Using typescript and if the first parameter for the Texture class is not a base texture, I get a warning so I never bothered to try it.

Share this post


Link to post
Share on other sites

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.