Hello again!
So I'm about to add some movement to the NPCs in my game. They have bump bodies but, the way I have been moving my player, for example, is by doing:
player:setPosition(x+1, y)
world:move(player, x+1, y) |
... Inside onEnterFrame().
But I feel that I shouldn't have decoupled movement like that. My question is, would I be better off doing something like creating a physics body, then adding the player table to
that? That way, when the body moves in world:move(), the player class is dragged around too?
Or does bump handle that automatically now? Like, it moves the bitmap and not just the physics body? And so if I did player:getX() it would accurately reflect where the player is, without ever having explicitly used setPosition()?
I'm not really sure that would work but one thing I am sure of; I've gone and confused myself again.
Comments
If you look at Box2d you will see that even though the physics objects move about and collide in the simulation.. you still have to extract their world position and use setPosition() on the sprite that represents that object on the display anyway
Likes: Astirian
I could use MovieClip to move the NPC and give him a time based on distance but then his physics body won't move. The only other options I can think of, is to either base it on a vector line (ew?) or use delta time:
1. Get the co-ords along a line to the destination and in each update() increment the x and y values based on points on a line, that seems terribly messy.
Or,
2. Use speed and delta time, I'm still trying to get head head around this but I've seen code snippets with it before and it feels more correct in terms of game coding patterns.
In terms of the latter, it looks like people usually do something like this in the frame update method:
player_speed = 60
player.y = player.y - player_speed * dt
player.x = player.x - player_speed * dt
Then invoke bump:move() with the new x and y coords. I need to understand per frame events more I think, but it looks to me like in this example, the player would move 60 "units" per frame. (I guess the dt is related to different processing speeds per device etc...)
The 60 can be anything I suppose, but I keep seeing FPS!
---
Update: OK, I started this post this morning and thought maybe I've answered my own question... Buuut, I'm having really weird effects with this code snippet I discovered. It's close I feel but it's also completely nutso:
Also, take a look on a Vectors. They are pretty useful Here is a playlist on youtube where you can find some info about this (search for "Character Movement" videos), and many other things.
Likes: Astirian, Apollo14
Likes: Astirian