Is it possible to have a camera follow your character in a 2D side scrolling game? I know you can use it in 3D, but I don’t know much about its use in 2D.
translate for 2d scrolling.
Go to the coolcodea blog, and read the series of post on making a 2D side-scroller. It’s got tonnes of great info
Sounds cool! Thanks @yojimbo2000
So, I couldn’t find anything on that blog that actually suited me. Could you help me out at all? @yojimbo2000
I was thinking about moving the entire world and keeping the character in place, but this a terrible approach as the game would lag for my larger worlds. In fact, my game is already lagging and it’s only attempting to draw like 30 dirt block sprites. I have no clue what I’m doing wrong with the lag.
I was thinking there would be some way to follow the character’s movements, and keep him centered on the screen. That’s the best approach, however I cannot figure out how.
@Ignatz you think you could help me out at all?
function setup() --define size limits of map that player can walk around in --define two opposite corners mapBottomLeft=vec2(-500,0) mapTopRight=vec2(WIDTH+500,HEIGHT*1.5) pos=vec2(WIDTH/2,HEIGHT/2) --player pos end --to move player, touch, on left or right of screen, or above or below the centre function AdjustPosition() local t=CurrentTouch if t.state==CANCELLED or t.state==ENDED then return end if t.x<WIDTH*0.5 then pos.x=pos.x-1 else pos.x=pos.x+1 end if t.y<HEIGHT/2 then pos.y=pos.y-1 else pos.y=pos.y+1 end --stop player going off the edge of the map pos.x=math.max(mapBottomLeft.x,math.min(mapTopRight.x,pos.x)) pos.y=math.max(mapBottomLeft.y,math.min(mapTopRight.y,pos.y)) end function draw() background(0) AdjustPosition() --this line centres the player translate(WIDTH/2-pos.x,HEIGHT/2-pos.y) --now draw everything normally --fill the whole map space with an image sprite("Cargo Bot:Starry Background",WIDTH/2,HEIGHT*0.75,WIDTH+1000,HEIGHT*1.5) --do your other drawing here --now draw the player fill(255,255,0 ellipse(pos.x,pos.y,50) end