Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path:shift()? #32

Open
saschagehlich opened this issue Jun 30, 2014 · 3 comments
Open

Add path:shift()? #32

saschagehlich opened this issue Jun 30, 2014 · 3 comments

Comments

@saschagehlich
Copy link
Contributor

I think it would be useful to implement a method that returns the first node of a path and deletes it at the same time.

@Yonaba
Copy link
Owner

Yonaba commented Jun 30, 2014

Can I have some use cases/examples where such a method would be really useful ?

@saschagehlich
Copy link
Contributor Author

Well, if I have a path and I'd like an object to move along this path, I will make it move from node to node. As soon as I reached the node, I will want to get the next node and I don't need to know about the previous node any longer.

@pancinteractive
Copy link

You can create this relatively easily by populating a table with all node values. I created something like this for use with Corona SDK, so you can move and actor along the path.

if path then
    print(('Path found! Length: %.2f'):format(path:getLength()))
    for node, count in path:nodes() do
    print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
    setX[#setX+1] = node:getX() -- populating coordinate table on each movement
    setY[#setY+1] = node:getY() -- populating coordinate table on each movement
    end
end

I assume this would be just as easy to bake into the actual library, but you know what they say about assuming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants