A little help? :)

Hey guys,

Just playing around with a few things using the Game Edition, and would like to know the best way to do 2 things.

A) Constrain a variable or text object value to the x attribute of a shape

B) The best way to create a loop for movement, or actions? So move left until a certain x value, then move right until another x value, repeat.

Thanks in advance :slight_smile:

// red. [import]uid: 7143 topic_id: 2757 reply_id: 302757[/import]

Thanks Mike, just what I wanted :slight_smile: (btw you missed off the closing “)” on the transitions :P)

Regarding A), to explain it better, how would I constrain player.x to a variable playerX that updates as frequently as possible?

Thanks

// red. [import]uid: 7143 topic_id: 2757 reply_id: 8295[/import]

Hi red,

a) That you have to do manually by .setText or .text depending on which object you have used

b) I hope that the following code works, did it without testing:

[lua]local onRight
local onLeft

function onRight(target)
transition.to(target,{time=1000,x=10,onComplete=onLeft})
end

function onLeft(target)
transition.to(target,{time=1000,x=310,onComplete=onRight})
end

local myObj = display.newImage(“image.png”,10,10)
transition.to(myObj,{time=1000,x=310,onComplete=onRight})[/lua]

Cheers
Michael

http://www.whiteskygames.com
http://www.twitter.com/mhartlef [import]uid: 5712 topic_id: 2757 reply_id: 8292[/import]

>>Thanks Mike, just what I wanted :slight_smile: (btw you missed off the closing “)” on the transitions :P)

Never, where , LOL thanks for the heads up, I corrected the missing “)”.

>>Regarding A), to explain it better, how would I constrain player.x to a variable playerX that updates as frequently as possible?

Like I said, via code. That is something for an “enterFrame” object event listener. You won’t be able to update it faster than that. [import]uid: 5712 topic_id: 2757 reply_id: 8306[/import]

Thanks Mike, however my enterFrame event listener doesn’t update :/… Is it something to do with the director class?

// red. [import]uid: 7143 topic_id: 2757 reply_id: 8329[/import]

Figured it out… I have no idea how I missed enterframe when it was meant to be enterFrame… damn code! :stuck_out_tongue:

// red. [import]uid: 7143 topic_id: 2757 reply_id: 8334[/import]