<Actor>.getWidth()

RayonMazter

  • Posts: 123
Returns the initial width of the actor, not the current.

If I grow/shrink the actor and call this, it doesn't return the correct values.

Ex: Actor of with 200
Shrink to 50%

<Actor>.getWidth() returns 200 still.

Hectate

  • *
  • Posts: 4643
I suspect that this is intended behavior. There just aren't any blocks for post-modification size without doing the math yourself with a modifier value.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

RayonMazter

  • Posts: 123
I disagree with that. When you make a call to get the width of an object, whether you have resized it or not, you expect to get the current size.

Not to mention this is also how it works in flash. When you retrieve the size of a movieclip or sprite, you get the current width, not the width of the object during designer mode.

However the .getWidth() command works, I would hope to get a low level result of the objects width, not a static value.

This is not a serious issue as yes I can calculate it myself, but that is more work and this engine is intended to simplify the process, not make it more difficult.


Hectate

  • *
  • Posts: 4643
As your question demonstrates, having the "corrected" width of the actor would definitely be useful. What I meant though was that internally, Flixel/Stencyl needs to track the width of an actor's sprite for various other purposes, and it probably uses the same function to do so. Changing that result could cause errors elsewhere.

The ideal solution would be to add the ability to get the width after scaling is applied without losing the current way. Maybe with just a parameter on the function to flag which result you're seeking to have returned from the call...
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Jon

  • *
  • Posts: 17524
This is our current implementation.


	
	
public function 
getWidth():Number
	
	
{
	
	
	
return 
frameWidth;
	
	
}
	
	

	
	
public function 
getHeight():Number
	
	
{
	
	
	
return 
frameHeight;
	
	
}


I suppose we could just auto-multiply by the current scale?

RayonMazter

  • Posts: 123
Even to add a combo item to the properties of 'CurrentWidth' as to not harm other projects upon such an update by modifying the other functions.

I also think it would be nice to add Set <Width/Height> to an object, instead of only having a 'grow' tween.

getCurrentWidth()
getCurrentHeight()
setWidth
setHeight


Requiring no tracking on our part for the sizes.

« Last Edit: December 04, 2011, 03:54:53 pm by RayonMazter »

BlackHC

  • Posts: 1
This is our current implementation.


	
	
public function 
getWidth():Number
	
	
{
	
	
	
return 
frameWidth;
	
	
}
	
	

	
	
public function 
getHeight():Number
	
	
{
	
	
	
return 
frameHeight;
	
	
}


I suppose we could just auto-multiply by the current scale?

That would be nice. I'm fighting with the same issue right now. I've stetched an object in the editor manually and now I need to access its actual size for some calculations.

I'm using the following function now, but it would be nice if getWidth() actually returned the real width of the object.


public function getCurrentWidth():Number
{
    return 
actor.currSprite.scale.actor.sprite.width;
}

« Last Edit: April 14, 2013, 04:32:12 pm by BlackHC »