darkshifty Posted March 6, 2020 Share Posted March 6, 2020 (edited) So I create a canvas as stated in the code below, with climateResources the textures are loaded (1024x1024) however because the screen is resized the sprites are resized to fit the screen. const app = new Application({ antialias: true, // default: false resolution: 1 // default: 1 } ); app.renderer.view.style.position = "absolute"; app.renderer.view.style.display = "block"; PIXI.AbstractRenderer.autoDensity = true; app.renderer.resize(window.innerWidth, window.innerHeight); document.body.appendChild(app.view); climateResources[gameLocation[0].name].forEach(arr => app.loader.add(arr)); app.loader.load(); app.loader.onError.add((loader, res)=>{ //error stuff }); app.loader.onProgress.add((loader, res) => { //console.log(loader.progress); //progress stuff }); app.loader.onComplete.add((loader, res) => { //complete, start setup setup() }); But I have no clue how to retrieve the resized size, I tried to retrieve the local position once a mouse down is clicked. But this does not honor the original size of the sprite, it gives some values from the absolute middle. But I cannot find on what it's based. this.sprite.on('mousedown', (e) => { console.log(e.data.getLocalPosition(this.sprite)); }) Result (this is not based on the 1024x1024 size of the sprite?): Top left: Point {x: -538.7999999999998, y: -536.9999999999999} Bottom right: Point {x: 537.5999999999999, y: 538.1999999999998} Does anyone know how I can retrieve the new size of my sprite in the mousedown or any other given moment so that I can calculate where the mousedown has taken place within my sprite? Or is there any other better method that I can use to record a click on a sprite? With thanks, Edited March 6, 2020 by darkshifty Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2020 Share Posted March 6, 2020 It should be (-512,-512) (512,512) because your sprite anchor is 0.5 , right? Please provide the demo on codepen/jsfiddle/pixiplayground. toLocal and toGlobal are easy to debug, just look which matrices they take from. Did you try to place breakpoint there and see how coords are changing? Quote Link to comment Share on other sites More sharing options...
darkshifty Posted March 6, 2020 Author Share Posted March 6, 2020 1 hour ago, ivan.popelyshev said: It should be (-512,-512) (512,512) because your sprite anchor is 0.5 , right? Please provide the demo on codepen/jsfiddle/pixiplayground. toLocal and toGlobal are easy to debug, just look which matrices they take from. Did you try to place breakpoint there and see how coords are changing? Thank you for your response, sadly it's close to 512 but not accurately. Here is a pixiplayground:https://www.pixiplayground.com/#/edit/v7prKywo4a4hzkGSw2xJo Both display a different size and position, if you open it on mobile its also different. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2020 Share Posted March 6, 2020 Your texture size is 1080. Coords are very close to 540 which is half. Sprite anchor is 0.5, so texture is positioned by its center in (0,0) Quote Link to comment Share on other sites More sharing options...
darkshifty Posted March 6, 2020 Author Share Posted March 6, 2020 41 minutes ago, ivan.popelyshev said: Your texture size is 1080. Coords are very close to 540 which is half. Sprite anchor is 0.5, so texture is positioned by its center in (0,0) Sigh... I feel so stupid now. I have been in a tunnel vision for three days. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 7, 2020 Share Posted March 7, 2020 Debugging and making sepearated tests helps to fight brain bugs. Believe me, I know of this state, I quite often find myself in it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.