How do i speed up a objects motion, and how do i make it move to the end of one side of the scree and come back on the other side
tejwinderthind - since the other thread is closed, here’s SonicX278’s question from it;
Can you explain “Speed up an object”? There could be a lot of answers for that.
For the object going from one side to the and coming out of other do you wan’t something like “Pixl escape” on google play?
–SonicX278
As they have indicated, there could be a lot of ways to ‘speed up’. As a starting point I would suggest checking out the following doc’s for creating physics bodies and moving them around at different velocities;
Cheers,
Simon
Dixon Court Entertainment
Wait what? Why close the topic that has a reply in it?..
–SonicX278
Sorry about that! I closed the wrong one.
My apologies
Haha no problem. I wasn’t mad. If I sounded mad.
–SonicX278
how to i get the object to come back on the other side of the screen
There’s an open source Corona game on github that implements that. Let me try to see if i can find it and get it to you.
–SonicX278
It’s called “Tilt Monster” on Google Play. Here’s the code from GitHub
https://github.com/l4u/Tilt-Monster
If you can’t get the code out for what you need I can do it a little later.
–SonicX278
i seem to be getting a error when i open the source code it would be much appreciated if you could assist me
Well without know what your error you are getting we can’t really help. Although I suspect it’s because this code is 4 years old and the SDK has changed a lot since (i.e. graphics 2.0, composer, etc). It would likely take a bit of work to actually get it to run, but you don’t need that. Just study the code to see what’s going on.
i would try to but theres about over 5000 lines of code and i did try to no succes
the only thing i need is a bar to keep repeating after ending on one side coming through the other
Hi,
There are two ways I’m aware of to accomplish this;
-
Have a runtime enterFrame event listener; set this to check if the object in question is off the screen (i.e. object.x < 0, or object.x > your screen width). If it is, it moves it to the other side of the screen. (I believe this is the method used in the sample given above.)
-
position sensors (physics bodies with .isSensor set to true) just off the screen on both sides, with collision event listeners, and when these are hit by the object they send it to the other side of the screen.
Which you go for would depend on a number of factors, including how the rest of your code is set up and personal preference; I’ve used both methods before (although not for this specific purpose), and both work equally well.
Cheers,
Simon
Dixon Court Entertainment
how do i constantly get it to update x and then collide and transition to the other side?
Hi,
The two numbered points I provided are two different ways of accomplishing it; you can EITHER have a runtime enterFrame listener, OR have sensors just off the edge of the screen which send the object to the other side of the screen. The question you replied with seems to be a mashup of both methods I suggested. As for how to accomplish them, if you follow the links I provided to enterFrame, isSensor and collision event listeners, that should give you a decent grounding in the principles needed for those two methods
Once you’ve had a go, feel free to post some code (remember to use the code format when posting code in the forums) and we can go from there.
Cheers,
Simon
Dixon Court Entertainment
both of the the things are static and don’t collide is there anyway to fix that and how do i set a function to repeat
Hi,
If the objects are both static, then they won’t collide - you always need one dynamic object in order to have a collision.
In which case you probably just want to have a runtime enterFrame event listener;
local myListener = function( event ) if yourObject.x \< -10 then yourObject.x = 810 elseif yourObject.x \> 810 then youObject.x = -10 end end Runtime:addEventListener( "enterFrame", myListener )
The runtime event listener at the end causes the myListener function to be called every frame while the app is running. All the myListener function does is check if yourObject is off the screen (I have used -10 for the left side, and 810 for the right side - you will need to update these to whatever you need to make it work for your app).
Cheers,
Simon
Dixon Court Entertainment
also how would i remove a object that is using that event without getting an error
(Attempt to compare nil with number)