Log In  

Hi guys; just bought pico-8 to use for the Game Jam and have some questions;

I'm following the platformer tutorial from Nerdy Teacher and was able to get my own status screen as show in the picture;

*the fanzine code I'm looking at is so I can remember how to draw a rectangle

What it does now is that the camera follows the player so when you progress the map the previous tiles will disappear where the new ones will show up; but when this happens the status box I made disappears along with it. I tried pasting and copying the code within the camera code I copied but that doesn't seem to work.

Is there a way where I can have the status text just stay static or doesn't move? Or move along with me?

The tutorial that I'm following: https://nerdyteachers.com/Explain/Platformer/

P#69693 2019-11-06 23:30

The easiest way to have static items move with your player is to - move them as well.

Try this code:

Cart #joyofufopi-0 | 2019-11-07 | Code ▽ | Embed ▽ | No License

P#69695 2019-11-07 01:33

Thanks for the help! But unless I'm doing it wrong; is the follow camera box supposed to follow the camera? because it's not doing that in the sample code you sent me

P#69700 2019-11-07 03:04
1

I'm not sure I know what you're asking. Follow camera box following the camera ?

Did you want a sprite to maintain in the center ? And remember that camera() does NOT adjust the screen. It adjusts what you plot AFTER that.

That's all it does. Important for you to know this. There is no function that actually shifts the screen.

Here is a variation with a center sprite and resetting the camera so you do not need to track it outside of the scrolling playfield.

Cart #yarafusudo-0 | 2019-11-07 | Code ▽ | Embed ▽ | No License
1

P#69701 2019-11-07 04:02

Oh I see what you're doing now; I got my menu to be static by adding camera() to the function but the camera made the scrolling goofy. Like now the physics has been altered

Here's my example

Cart #sekohimizi-1 | 2019-11-07 | Code ▽ | Embed ▽ | No License

P#69706 2019-11-07 05:30 ( Edited 2019-11-07 05:40)

I'll be honest, I don't program like this if I can at all avoid it. Using _draw() and _update().

Let me think on your problem here, but if some other veteran wants to answer they are welcome to.

P#69707 2019-11-07 06:23

It's because you're drawing the actors after resetting the camera. They're drawn in the wrong place relative to the map.

You want to be doing something like this:

function draw_game()
  camera(cam_x, 0)
  -- draw map and actors here
  camera()
  -- draw status bar here
end

Basically, call camera() with arguments before drawing things in the world and without arguments before drawing things on the screen. You can think of it as switching between different coordinate spaces.

P#69712 2019-11-07 06:59

Ohh that seemed to work; Let me see if I can understand this

the first camera(arg1, arg2) sets the main camera for the map? Which makes the map scroll with the player

where the 2nd camera() resets what's going on and anything under it will scroll with the player even though the first camera() already has it set?

P#69721 2019-11-07 16:25
1

Yep, that's about right.

All the camera function really does is add offsets to the coordinates given to subsequent drawing commands. A call with no arguments resets them to 0.

camera(10, 20)
spr(1, 70, 90) -- actually draws at 60, 70

camera(70, 90)
spr(1, 70, 90) -- actually draws at 0, 0

camera()
spr(1, 70, 90) -- actually draws at 70, 90

But it's useful to think of it in a more abstract way. If you imagine an actual camera looking at the map at position cam_x, cam_y, calling camera(cam_x, cam_y) switches the view to that camera, and any drawing done after that is done as though you were looking through it. The status bar doesn't exist in the world and shouldn't be viewed through that camera, so you call camera() to switch away from it and draw directly on the screen.

P#69722 2019-11-07 17:38

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:03:00 | 0.013s | Q:31