Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Set sprite then set spritePosition

A topic by Ilphrin created Sep 15, 2016 Views: 465 Replies: 5
Viewing posts 1 to 6
Hi!

I have a behavior which need to set its sprite some time after its initialization, I can do it pretty easily with X.spriteRenderer.setSprite(). But now I need to set the size of the sprite, is there a function, for example:

X.spriteRenderer.setSize(32, 32);

You can't change the size of the sprite [ the image ], but instead you can change the size, or scale, of the actor itself using these methods:

this.actor.getLocalScale()
this.actor.setLocalScale()

Best way i know to modify size of the sprite is to change the scale of the actor with the spriteRenderer (considering that it would also scale its children). So the way to go would be:

X.setScale(1, 1, 1);

Where the scale will be in pixel units, if you have setting 64 pixel units and want the sprite to look like if it where 32 pixel unit then the scale might be 0.5. (dont take my word here, its what i imagine happen)

The other way is changing the pixel unit property on the sprite editor, that way the sprite will always render at the equivalent size.

Thanks guys! I have set the scale to 0.1 and it works perfectly! =D the function I used is the one superpowers autocompleted me x)

this.actor.setLocalScale(0.1, 0.1, 1);

would it be more efficient to possibly resize the sprite images as well so that your not downloading as large of an asset from the web?

Well, I need different sizes depending on when I want to load this asset (but sure I could resize them to half of their size at least xD)