Assigning code to objects

Hello,

I hope I’m asking this to the correct forum.

Let’s assume that we have clouds moving from top to bottom. When the object is at the bottom and out of screen, I want to reposition it to the top and do the same thing all over again.

I believe we can accomplish this by assigning a runtime enterframe listener to check it every frame.

But as far as I know this is costly in terms of performance. Especially if we have several of this type of listeners.

So being an ancient flash coder, I tend to think in actionscript. I used to attach scripts to objects, and let them carry out their own tasks, instead of checking them from a central entity. In this particular case, I would like the clouds to move themselves to top… but how? There must something to this that I can’t comprehend :slight_smile:

Thank you very much

Kaan [import]uid: 99031 topic_id: 32430 reply_id: 332430[/import]

How are the objects being moved. Transition.to, physics, translate, other ? [import]uid: 7911 topic_id: 32430 reply_id: 128957[/import]

At the moment, I am controlling them via a runtime event listener, updating their .y position constantly. I guess this is the same as translate. Actually it doesn’t really matter as long as they control themselves as I mentioned.

[import]uid: 99031 topic_id: 32430 reply_id: 128976[/import]

Where u change the y pos. do something like this
object.y =( (object.y + unit)%(display.contentHeight + object.height)) -object.height [import]uid: 7911 topic_id: 32430 reply_id: 128977[/import]

My solution is almost exactly like this and it works. But what I would like to know is if there is another way than frantically updating the .y position via a function. Like saying “ok object here is what you need to do”. For instance, checking itself if it is moved out of visible area and killing itself accordingly, instead of checking this via a an enterFrame listener. [import]uid: 99031 topic_id: 32430 reply_id: 128978[/import]

Only other thing I can think of is

[code]
function moveCloud()
object.y = -100
transition.to( object, { time=…, y = display.contentHeight + object.height, onComplete = moveCloud})
end

moveCloud()

[import]uid: 7911 topic_id: 32430 reply_id: 128980[/import]

R ur clouds individual objects or one object with multiply cloud images [import]uid: 7911 topic_id: 32430 reply_id: 128981[/import]

R they just for visual r do they need to react to other objects [import]uid: 7911 topic_id: 32430 reply_id: 128982[/import]

Thank you, that is also a way to do it. Please excuse my lameass questions, but is this the general methodology in Corona / Lua? Maybe it’s because of my actionscript habits, but for instance in Unity you simply write a script and attach it to an object, and object handles the rest itself. This kinda makes more sense to me.

Again, thank you very much

K. [import]uid: 99031 topic_id: 32430 reply_id: 128984[/import]

I haven’t used AS or unity so I couldn’t compare [import]uid: 7911 topic_id: 32430 reply_id: 128985[/import]

ok thank you :slight_smile: [import]uid: 99031 topic_id: 32430 reply_id: 128986[/import]

How are the objects being moved. Transition.to, physics, translate, other ? [import]uid: 7911 topic_id: 32430 reply_id: 128957[/import]

At the moment, I am controlling them via a runtime event listener, updating their .y position constantly. I guess this is the same as translate. Actually it doesn’t really matter as long as they control themselves as I mentioned.

[import]uid: 99031 topic_id: 32430 reply_id: 128976[/import]

Where u change the y pos. do something like this
object.y =( (object.y + unit)%(display.contentHeight + object.height)) -object.height [import]uid: 7911 topic_id: 32430 reply_id: 128977[/import]

My solution is almost exactly like this and it works. But what I would like to know is if there is another way than frantically updating the .y position via a function. Like saying “ok object here is what you need to do”. For instance, checking itself if it is moved out of visible area and killing itself accordingly, instead of checking this via a an enterFrame listener. [import]uid: 99031 topic_id: 32430 reply_id: 128978[/import]

Only other thing I can think of is

[code]
function moveCloud()
object.y = -100
transition.to( object, { time=…, y = display.contentHeight + object.height, onComplete = moveCloud})
end

moveCloud()

[import]uid: 7911 topic_id: 32430 reply_id: 128980[/import]

R ur clouds individual objects or one object with multiply cloud images [import]uid: 7911 topic_id: 32430 reply_id: 128981[/import]

R they just for visual r do they need to react to other objects [import]uid: 7911 topic_id: 32430 reply_id: 128982[/import]

Thank you, that is also a way to do it. Please excuse my lameass questions, but is this the general methodology in Corona / Lua? Maybe it’s because of my actionscript habits, but for instance in Unity you simply write a script and attach it to an object, and object handles the rest itself. This kinda makes more sense to me.

Again, thank you very much

K. [import]uid: 99031 topic_id: 32430 reply_id: 128984[/import]

I haven’t used AS or unity so I couldn’t compare [import]uid: 7911 topic_id: 32430 reply_id: 128985[/import]