### What does speed mean?

#### ProMole

• Posts: 80
Here's an information I've found oddly hard to discover: what does speed mean in Stencyl?

Here's the thing, we can set the speed of an object, be it by setting the x and y components or the value and directoin, but what does that value mean? What is the unit here? Is it pixels per second? Pixels per 60 frames(or whatever is the actual fps)?

I had to find a way to create new rows of blocks in my game, but I had no idea how to figure out when they would be aligned, or when they would have walked one tile high. I ended up creating an invisible object at the same speed and tracking its position. It's... clunky, but worked.

I just can't find it in the docs, and the forum search gets a load of stuff that's unrelated so I just had to ask. =/

#### LewCorp

• Posts: 163
I think speed is measured in Pixels per Second, if you look at an Actor moving when the speed is set to for example 1, then you can sell that every time it moves, it looks as if it is only moving about a pixel.

#### Photon

• Posts: 2691
1 Unit of Speed = ~10 Pixels per second
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

#### ProMole

• Posts: 80
So, with the daze of getting a game done with a tight deadline gone I finally sat down and devised a test to find that out by myself. The answer is interesting.

Speed = pixels / 10 frames.

Yep. Speed 16 means 1.6 pixels per frame, or 16 pixels per 10 frames. This means that in the ideal 60fps game an object will move 6 times faster than its designated speed.

That makes predicting position pretty hard, thus, but it was even worse: because my object speeds were not multiples of 10(16, for example), slips were common because floating point operations are tricky. Redesigning the parameters to be multiples of 10 or 5 let me get rid of some weird gaps between rows of blocks.

So now we know.

#### Photon

• Posts: 2691
I think your calculations are off. I'm not the only user who has tried to figure out speed, and from what I've seen we all have come to approximately the same result: 1 unit of speed equals 10 pixels per second.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

#### ProMole

• Posts: 80
Ok, so let me tell you what I did.

1) I created an Actor. A ball. It has no behaviors, no physics.
2) Created a scene with a behavior.
3) In this behavior, I create 5 balls, each with speed 16 units bigger than the previous, starting with 16. Thus, 16, 32, 48, 64, 80. All start on x 0.
4) Then in the update event I set the behavior to print out the position of each of the balls, for the first 5 updates.

Here are the results:

The conclusion I get is still the same: 1/10 of speed per frame. There you go.

#### Photon

• Posts: 2691
An actor's real position can't have decimal places; I'm not sure what you are printing.

Can you screenshot the code you are using to manipulate the balls and print the information?
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

#### Hectate

• Posts: 4643
Floating point errors can introduce them though. Always fun when you have a check like "x ==z" and it doesn't work so you print the value and it's like z.9999999 instead.
 :: 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.

• Posts: 1795
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

#### Photon

• Posts: 2691
Been calculated before: http://community.stencyl.com/index.php/topic,22847.msg131891.html#msg131891
Not sure if there's a difference, but that's referring to when using the "slide" block.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

• Posts: 1795
Been calculated before: http://community.stencyl.com/index.php/topic,22847.msg131891.html#msg131891
Not sure if there's a difference, but that's referring to when using the "slide" block.
In that post my reply stated that using slide with no effects (bounce in/out etc) is the same thing as setting X Speed for an actor. I had at the time made a simple test where one actor was moving with a slide block and one was moving with a x speed block and they both moved at the same time.
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

#### ProMole

• Posts: 80
There you go, this is the code.

Code: [Select]
public dynamic class StartBalls extends SceneScript
{
//Expose your attributes to StencylWorks like this
[Attribute(id="1", name="Display Name", desc="An Attribute")]
public var attributeName:String;
//Then in the constructor or init(), add it to the nameMap like this
//nameMap["Display Name"] = "attributeName";
//This lets API calls using attribute names to use the display name

//Do all actor initialization here

var balls:Array = new Array();
var frames:int = 5;

override public function init():void
{

for (var i:int=1; i <= 5; i++)
{
var thisBall:Actor = createActor(getActorTypeByName("Ball"),0,32+i*32,MIDDLE);
thisBall.setXVelocity(i*16);
balls.push(thisBall);
}
}

//This is executed every frame of the game
public function update(list:Array):void
{
if (frames > 0)
{
for each (var ball:* in balls)
{
print(ball.getX());
if (ball.getX() > 320)
balls.remove(ball);
}

print("----------");
frames--;
}
}

public function draw(list:Array, g:Graphics, x:Number, y:Number):void
{
}

public function handleCollision(list:Array, event:Collision):void
{
}

//Leave this alone. Do your initializing inside init()
public function StartBalls(ignore:*, scene:GameState)
{
super(scene);
}
}