I want to create an object that is moving in a random direction when it hits the stage, any ideas? Thanks!
Kevin [import]uid: 96383 topic_id: 16474 reply_id: 316474[/import]
I want to create an object that is moving in a random direction when it hits the stage, any ideas? Thanks!
Kevin [import]uid: 96383 topic_id: 16474 reply_id: 316474[/import]
Hey!
So you can do this easily I think…!
I’d say just do this…
and you can replace ball with your object!
and tweak anything else
[code]
local movespeed= math.random(-50,50)
local ball= display.newCircle(10,10,25)
function ball:enterFrame(event)
ball.x= ball.x+movespeed
end
Runtime:addEventListener(“enterFrame”,ball) [import]uid: 95032 topic_id: 16474 reply_id: 61461[/import]
That’s cool! Thanks a bunch. So the Runtime command is used to initiate a function when the program starts? [import]uid: 96383 topic_id: 16474 reply_id: 61468[/import]
Runtime just means “every frame” pretty much… I’m not sure what you mean by that initiating… but all you want is know that Runtime:addEventListener(“EnterFrame(which is every frame)”,and your object which has That EnterFrame… You an do ball.y also! [import]uid: 95032 topic_id: 16474 reply_id: 61474[/import]
If you want to “initiate” something when the app starts, you do it like so;
[lua]function()[/lua]
Obviously using the function name rather than “function”
[import]uid: 52491 topic_id: 16474 reply_id: 61636[/import]
Thanks peach! I’m really getting a lot out of your tutorials, btw. And so gratified that help is so close at hand from Ansca staff. This platform is fantastic.
[import]uid: 96383 topic_id: 16474 reply_id: 61685[/import]
Thanks very much for the kind words - I really love it when my tutorials can help people and more than that, I enjoy it when people have a good experience with the forum and community 
Peach [import]uid: 52491 topic_id: 16474 reply_id: 61738[/import]