Fed up with this issue that I cannot figure out

There’s an issue on the game I’m working on. It’s a fairly simple game, so I don’t know why I’m stumped on this. Keep in mind, I’m pretty new to programming apps. The most I’ve done is BASIC. This language seems simple, but it is not as it appears to be.

Anyways, I’m trying to get a character to move up or down the screen depending on which button is pushed.


Aside from that, how do you move an image?


Also, how do I create progressing bars that move back when hit with say a square shape?


I’m sorry to ask all these questions, but it has stumped me, as I am a newcomer to this Corona language. [import]uid: 48020 topic_id: 12990 reply_id: 312990[/import]

If no physics are involved, this will move your character 1 pixel per loop on the x axis.

To only move when the button is pressed, you can create a variable that checks if the button is being held down using listeners and only run that line of code within the game loop when the button is held down. (http://developer.anscamobile.com/content/application-programming-guide-event-handling#Hit_Events)

local function gameLoop(event)  
 character.x = character.x + 1  
end  
  
Runtime:addEventListener("enterFrame", gameLoop)  

If you are planning to implement physics then:
http://developer.anscamobile.com/content/game-edition-box2d-physics-engine [import]uid: 75783 topic_id: 12990 reply_id: 47644[/import]

Or, if you just need to move a character from point A to point B, transition.to() is your friend:

[lua]transition.to( cuteCharacter, { time=1000, x=480, y=200} )[/lua]

That will move your object to the position 480, 200 in 1 second (the 1000 milliseconds shown in the code).

You may need the “fine control” that you can get with a game loop as shown in the previous example, but in many cases transition.to() may be all you need.

http://developer.anscamobile.com/reference/index/transitionto

Jay
[import]uid: 9440 topic_id: 12990 reply_id: 47651[/import]

If it helps I have a D Pad tutorial on http://Techority.com :slight_smile: (I’m not sure what kind of movement you want specifically but it’s a nice gentle starting point.)

Peach :slight_smile: [import]uid: 52491 topic_id: 12990 reply_id: 47668[/import]

Peach’s tutorial is solid. I am all about using tilt, but this got me thinking in terms of attaching/linking actions to my main character.

Also for what it’s worth, I found this and I am using this for some platforms in my game.

All this does is move an object back and forth. If you are like me you can look at things and go “I like this and NOT that, ok I want to extract this and that, but not THAT” or something…

anyway, here you go just plug n play into a main.lua file and launch you see what I mean

-Nick G aka G$

[code]
–Object back and forth animation
object = display.newRect( 0, 0, 50, 50)
object.x = 100

function goLeft ()
transition.to( object, { time=1500, x=(object.x - 50), onComplete=goRight } )
end

function goRight ()
transition.to( object, { time=1500, x=(object.x + 50), onComplete=goLeft } )
end

goLeft()
[/code] [import]uid: 61600 topic_id: 12990 reply_id: 47774[/import]