Page 1 of 1

moving an object along a freehand line

Posted: Sat Feb 27, 2016 5:07 am
by ethanCodes
I am making a Tower Defense game for a class and am trying to get the image of the "enemy" to move across the screen. I can't seem to get it to work though. I watched a tutorial online of something similar and thought I had it figured out but it's not doing anything. Here is what I've got so far:

this is attached to the image "Miner" card (the Miner is the enemy)

Code: Select all

on cardOpen
   move image "Miner" to the points of graphic "pathEnemy" in 10 seconds without waiting
end cardOpen
and this is attached to the card script:

Code: Select all

on preOpenCard
   set the location of image "Miner" to 44.713
end preOpenCard

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 5:21 am
by quailcreek
Hi Ethan,
You are confusing LC. You are telling it to do something in 10 seconds without waiting. You can either say in 10 seconds or you can say without waiting but not both. If you say 10 seconds, it will take 10 seconds for the image to traverse the path. If you say without waiting, LC uses a system moveSpeed value to traverse the path.

Code: Select all

    on cardOpen
       move image "Miner" to the points of graphic "pathEnemy" in 10 seconds
    end cardOpen

Code: Select all

on mouseUp
   set the moveSpeed to 50
   move image "Miner" to the points of graphic "pathEnemy" without waiting
end mouseUp

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 5:55 am
by ethanCodes
ah I see! Thank you!

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 6:00 am
by ethanCodes
So I changed that but I'm getting an error for the code that is supposed to set the location of the Miner image.

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 6:03 am
by ethanCodes
and even if I comment out that code, it still doesn't move...

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 6:55 am
by quailcreek
It should be 44,713 not 44.713

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 10:41 pm
by capellan
Hi ethan,

Are you making a game?
You need to learn about the game loop.

Visit Scott McDonald's website:
http://livecodegamedeveloper.com/index.html
and check this article:
http://livecodegamedeveloper.com/blog/2 ... de-pong.lc

You could read (and learn) from his games and
after reading all his posts, you can buy his book
to learn all his game making algorithms and techniques:
http://livecodegamedeveloper.com/book.html

I bought his book months ago, an learned a lot
about his techniques.

Have a nice weekend!

Alejandro

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 11:45 pm
by ethanCodes
ah I see, I didn't catch that period! Thank you! I will see if this works. Also, thank you Alejandro for the links!

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 11:49 pm
by ethanCodes
it still does nothing.

Re: moving an object along a freehand line

Posted: Sat Feb 27, 2016 11:58 pm
by quailcreek
Then there must be something else in you code that's stopping it. See if this helps.
Maybe it's openCard not cardOpen

Re: moving an object along a freehand line

Posted: Sun Feb 28, 2016 2:25 am
by ethanCodes
so if I change it to on mouseUp it works, but I need it to start by itself after a certain amount of time. I know how to set the time, but for now I just want it to start immediately. But for whatever reason it won't do anything with the on openCard (and you were right it is on openCard, not on cardOpen).

Re: moving an object along a freehand line

Posted: Sun Feb 28, 2016 2:33 am
by ethanCodes
I figured it out! the code to move the miner can only be "on openCard" if it is on the card's script, not the miner's script.

Re: moving an object along a freehand line

Posted: Sun Feb 28, 2016 2:55 am
by quailcreek
Good for you, Ethan. You were able to figure out the problem. You're on your way to writing some great apps.