get width or scale.x of scaled actor

Gintonic

  • Posts: 69
Hi,
I've added an actor in the sceen and scaled it (editor). Now I need the width or scale factor during runtime. The problem is, I get the width of the original actor (100%). I've tried this:

print[Code:[actor.sprite.width]]

width is the width of the original actor, not the scaled

print[Code:[actor.bodyScale.x]]

scale is 1

print[Code:[actor.currSprite.scale.x]]

[LOG] Msg =  com.stencyl.models.Actor has no field currSprite


Do anybody know how to get the current width or scale?

Thanks a lot.

Meestar

  • Posts: 654
Well, if you've scaled it in the editor then take the scale amount and multiply it by the width or height.
PM me if you require help.  I'm always glad to help out!

Gintonic

  • Posts: 69
I want to add more instances of the actor in the editor scaled differently. I need the real width or scale in the event of the actor.


captaincomic

  • *
  • Posts: 6108
Are you using the 3.0 beta? ("com.stencyl.models.Actor" looks like it's from the 3.0 API.)

For 3.0 the actor.bodyScale.x/y should work:
EDIT: (wrong link) http://community.stencyl.com/index.php/topic,21026.msg133194.html#new





« Last Edit: June 19, 2013, 05:06:13 am by captaincomic »

Gintonic

  • Posts: 69
Yes, 3.0 beta. To simplify it, in the balloon game I've added an "when created" event

print [ Code: actor.bodyScale.x ] block

to the Reset Button actor.

Then I scaled the button in the editor to 0.5

When I start the game, I still get 1 as result:

[LOG] [Flash] scripts.ActorEvents_19#init(57): 1

captaincomic

  • *
  • Posts: 6108
Hm, okay, I never tried it myself. You could try the custom blocks in the behavior attached in the other thread to see if they work.

Gintonic

  • Posts: 69
I think, you posted the wrong link, but I've tried Owen's custom block, with the same result.

http://community.stencyl.com/index.php/topic,21026

[Oh, I see the link is the same...]

Innes

  • *
  • Posts: 1960
I've never tried it, but if you assign two actor values (e.g. ScaledWidth and ScaledHeight), you could update those values whenever the actor is scaled.

You could then read the actor values to discover the scale of the actor.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Gintonic

  • Posts: 69
Yes, but this is very unhandy when you have many different scaled actors in the scene editor. Just wonder, if the bodyScale command is buggy or I do something wrong...

Meestar

  • Posts: 654
Well, you could instead scale them through a behavior and edit the values in the inspector, thus allowing you to do the math I mentioned above.
PM me if you require help.  I'm always glad to help out!

Gintonic

  • Posts: 69
Ok, now it works for me. I've found out, that actor.bodyScale.x only works, if the phsysics setting is set to "Cannot be pushed" or "Normal". If you select "Cannot move" the value is always 1.
Thank you all for your help.