[SOLVED] A Simple Question About width, height, halfWidth, halfHeight


(Bora Kasap) #1

That one works perfect:

x = FP.world.getInstance("playerx").x;

Also that one works perfect too:

x = FP.world.getInstance("playerx").x + 20;

But when i use this:

x = FP.world.getInstance("playerx").x + FP.world.getInstance("playerx").halfWidth;

it returns the same value with this one:

x = FP.world.getInstance("playerx").x

(Jacob Albano) #2

My guess is that you never set the width of your player’s hitbox, and you’re expecting it to return the width of the image.

You can set the hitbox to the size of the image like this:

graphic = myImage; // or spritemap, or whatever.
setHitboxTo(graphic);

(Bora Kasap) #3

It worked. Just a few minutes ago, i was set hitbox like that:

setHitBox(width, height);

Now, it seems thats the problem. I wasn’t know width and height are belongs to hitbox.

Thanks so much.


(Abel Toy) #4

yo, storing your player instance on a local variable will make this a bit better!

var player:Entity = world.getInstance("playerx");
x = player.x + player.halfWidth;```

![Clippy](https://si0.twimg.com/profile_images/220088564/clippy.png)

(Bora Kasap) #5

Yeah, i want to use it but everytime i try it, it is returning an error about “static type”