Please help with this basic topic camera always follow the character

I need to make the camera always follow the character in my game. This is my code: 

display.setStatusBar( display.HiddenStatusBar )

local fisica = require(“physics”)

physics.start()

physics.setDrawMode(“normal”)

physics.setGravity(0,9.8)

local fondo display.newImage (“sky2.bmp”)

local suelo = display.newImage (“suelo2.png”)

suelo:setReferencePoint( display.BottomLeftRferencePoint)

suelo.x, suelo.y = 160, 470

physics.addBody (suelo, “static”, {friction = 1.0, density=1.0, bounce=0,})

local paredIz = display.newRect( 0, 0, 1, 480 )

physics.addBody (paredIz, “static”, {friction = 1.0, density=1.0, bounce=0})

local ninja = display.newImage (“ninja.png”) 

physics.addBody (ninja, {friction = 0.25, density=1, bounce=0.2, radius=37})

ninja.isFixedRotation = true

– Disparo tipo angry birds–

function moveNinja( event )

    if event.phase == “began” then 

        display.getCurrentStage( ):setFocus(ninja)

        elseif event.phase == “ended” then

        ninja:applyLinearImpulse(event.xStart - event.x, event.yStart - event.y, ninja.x, ninja.y)

      display.getCurrentStage( ):setFocus(nil)

    end

end

ninja:addEventListener( “touch”, moveNinja)

I need to know how to create a group and how to make the camera always follow my character. Thanks

Please use titles in your post that ask the question you need to know, like “How do I make my camera follow my character?”  You will get better responses.

This is a question that comes up with some frequency.  You should be able to search for this either with our search above or with Google to get your answer.

Rob

i delete this because i dont want to hurt susceptibilities. i  prefer continued by my self.

have you looked in the code exchange. or perhaps google as rob suggested. this link was the third one down searching for corona sdk camera
http://developer.coronalabs.com/category/tags/camera

@danielmuvdi I don’t usually respond to anyone posting the way you have, but your question is usually the sort of problem I would jump on and can actually provide many different answers to (and have in the past.) I’m not going to because you’re being so intolerable. If you don’t like the community don’t blame the system, just leave. I and the others here who don’t work for Corona Labs but still enjoy the community find people like you annoying and it will be a matter of time before your account is recommended for blocking. Put up or shut up.

@danielmuvdi What a rude post! The corona forum are really great and answered quickly. A large part of the problem is the type of question - it’s impossible to reply to such a big topic with a simple few lines of code. Like Rob suggested there are several soultions to this already available. It’s a bit old now but there is a project named ‘Ghosts vs Monsters’ that has what you need. It could be the case that you need to go back to the basics before attempting something like this.

5 posts and you’re claiming: “…why the community its decreasing really fast”

Wow - I’d actually say the reason why the community could fail is because of the increase of people who expect to have everything served to them on a plate, without actually going to any lengths to try to solve the problem.

Both Matt and Jason here are always on hand to help people - the community is awesome, however newbie coders need to understand that coding is difficult and you can’t just create the next GTA in 5 minutes.

I’ve lost count of the number of times I try to suggest newcomers start off simple so not to become disillusioned - but it rarely happens.

i can find 300 post with people how think exactly like me, and the answers  its always the same, look on the forum, well on the forum is not the answer. and the  difference  with me is  the other people just go away. but i was to tying to make the people on this community reales of this situation, if you don’t want to help its fine, but its more rude to answer. look for the  answers on the forum,  because, if some one take the time to ask, its because probably its trying so hard to find the answer  without   success., its my second post, i been reading this forum for almost one year, and almost 50% of the question are  without  answers  , and yes i was rude, i never in mi life was rude with people on forums. but i was trying to see if the people  prefer  fight to help, and the  answer  its yes. you guys prefer fight with some one how its trying to study, but when the same person ask for help no one  comment  and answer. 

thanks and sorry if i was rude but some time its  frustration.

pd : thanks a lot  Jstrahan!  i go to see that,  because i find this ( camera = display.newGroup()) but not work for me.so probably that work thank for your time and your good intention to help me.

 

your welcome
now with that said in future if you want help ask nicely and you’ll get more help. if someone doesn’t answer that mean either no knows the answer. or your question was missed. I’ve been here from close to the beginning and have several questions unanswered. but instead of getting upset about I kept doing research. it is frustrating when someone asks a question that can be easily found as your camera question. it took me about 10 seconds to find. although your question above was not directed at me personally it felt as if it was and I wanted to respond as everyone else but in the end I decided to just give the answer and state how easy it was to find
now to answer your new question. most code in the code exchange is for gpx1.0 corona now uses gpx2.0 so you will need to go though it and make the required changes. there’s a migration guide in the online guides that tells what changes need to be made. hope this helps and in the future please have a little more respect for others who give their time freely

As with jstrahan I’ve been here for over 3 years and I take the most joy in answering those posts which have 0 replies - especially the physics questions. However, I’ve only got so much time in the day and I only know so many answers. So, when there are posts which only someone with my particular experience in a particular field go unanswered its because there is no-one to answer at that time. As you can see, the “recent” posts are listed in chronological order and if no-one answers for a while they can easily be lost inside a few short hours.

Well thanks again i dont know yet if its go to work or not(all the link are bad,  the code its old,and i  see that link before i make the question), but you give me an answer and i  appreciated that, its  different  to say look on the forum to give some one a answer. like if the person how its making the question was stupid or something. i help people every day in forums about stock market, and i answer the same question alll the time. because i know how  frustrating  is when you start with something. about my question i think its not rude at all. my first question was normal and i think i was nice. but i have a bad answer like other 500 people in the forum i jus get really frustrate about it.  i  appreciated  your help and i can now go away like horacebury  suggest,. how is the rude? i dont think i make a bad question.but at the end i can have some  attention  and that was my intention

its never bad to help some one. and when i can help some one with corona i go to do it. i like help people. if i now the answer.

THANKS AGAIN.

Pd: I love corona and i love the people here,  i go to start paying for pro when i get ready… i bought all the courses and i have the decision to learn. but if some time  some one ask a basic simple question and if you dont know the answer or you know the answer but you dont want to help pls, dont tell him look on the forums. its just rude.

Well i solved by my self,  and i go to SHARE the code if some one its starting like me and dosent now how do it.

Is really simple. 

– create a group–

local game = display.newGroup( )

–insert the objects on the group.–

game:insert(suelo)

game:insert(ninja)

–create a simple  function  based on what you wan to do, in this case i want to  fallow  my character with the camera. you can also make camera movements like showing all the level for example –

 function loop( )

    

    game.x = 160 - ninja.x

end

– and the last step its create a listener with enterFrame—

 Runtime:addEventListener( “enterFrame”, loop )

this was really easy!

ok good code  every  one!

Yes, I always find that I eventually work the answer out myself if I start my questions with an accusation against the very people I’m asking for help from.

Horacebury man you have to move on… the problem is solved.  every  one is fine.

Thanks for your time.

Please use titles in your post that ask the question you need to know, like “How do I make my camera follow my character?”  You will get better responses.

This is a question that comes up with some frequency.  You should be able to search for this either with our search above or with Google to get your answer.

Rob

i delete this because i dont want to hurt susceptibilities. i  prefer continued by my self.

have you looked in the code exchange. or perhaps google as rob suggested. this link was the third one down searching for corona sdk camera
http://developer.coronalabs.com/category/tags/camera

@danielmuvdi I don’t usually respond to anyone posting the way you have, but your question is usually the sort of problem I would jump on and can actually provide many different answers to (and have in the past.) I’m not going to because you’re being so intolerable. If you don’t like the community don’t blame the system, just leave. I and the others here who don’t work for Corona Labs but still enjoy the community find people like you annoying and it will be a matter of time before your account is recommended for blocking. Put up or shut up.

@danielmuvdi What a rude post! The corona forum are really great and answered quickly. A large part of the problem is the type of question - it’s impossible to reply to such a big topic with a simple few lines of code. Like Rob suggested there are several soultions to this already available. It’s a bit old now but there is a project named ‘Ghosts vs Monsters’ that has what you need. It could be the case that you need to go back to the basics before attempting something like this.

5 posts and you’re claiming: “…why the community its decreasing really fast”

Wow - I’d actually say the reason why the community could fail is because of the increase of people who expect to have everything served to them on a plate, without actually going to any lengths to try to solve the problem.

Both Matt and Jason here are always on hand to help people - the community is awesome, however newbie coders need to understand that coding is difficult and you can’t just create the next GTA in 5 minutes.

I’ve lost count of the number of times I try to suggest newcomers start off simple so not to become disillusioned - but it rarely happens.