Discuz! Board

 

 

Search
Discuz! Board Forum Integration Questions Is there a way to get the image size for a sprite?
View: 529|Reply: 1
go

Is there a way to get the image size for a sprite?

Rank: 3Rank: 3

Post on 2011-7-4 16:01 |All posts
When I add a sprite and immediately after creating or adding the image, check the size of the image, I get [0,0] in the size.

var itemImage = sprite(imagePath);
someBtn.add(itemImage, 1, 1);
var sizeImage = itemImage.size();
trace("sizeImage", sizeImage);

Is there any way to get the actual size of the image at either the point when you create the sprite or when you add it to its parent? I need to do some image manipulations based on the size of the image.

Rank: 4

Post on 2011-7-4 16:31 |All posts
var scene = getscene();
var spr = scene.addsprite("fish.png").prepare();
trace("size:",spr.size());

call prepare(), then node's size will be image's size. Call it only when the images are in the APK or you are sure it has been download to phone 's storage.

Because images may not be ready when calling addsprite(), so we implement prepare() API to update size later.
Security Q&A Change Security code Change

Archiver|Comsenz Inc.

All time is GMT+8, 2013-5-22 19:46 , Processed in 0.030586 second(s), 10 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.