Log In  


Cart #kafadimiji-0 | 2025-07-26 | Code ▽ | Embed ▽ | No License
1

Regarding to the title, I tried to make a camera function which has 2 behaviors.

  1. Between room and room : Transition just like Zelda series
  2. In a large-sized room : Scrolls just like Mario series

However, 1.'s transition animation won't work. Screens just change instantly...

What should I do to solve this problem? Thanks in advance.

1


1

Cart #kafadimiji_camfix-0 | 2025-07-27 | Code ▽ | Embed ▽ | No License
1


It turned out to be unexpectedly complicated.
The big problem was the timing of obtaining get_current_rooms().

The room is obtained in check_room_transition() and compared with the player's coordinates, but because it is always obtained from the current player's coordinates, there will be no difference between the room and the player no matter where you move.
For this reason, when switching to a different room, no transition occurs, and only the camera switches according to the room coordinates.
I saved the destination room along with the transition flag.

The function name was changed because the meaning changed.
get_current_rooms() -> get_player_rooms()

The commented out parts are the parts that fix other issues.


1

Shiftalow-san, thank you so much for your fix & explanation!
Now I got what was happening and how that was fixed.


1

Cart #gajarikari-0 | 2025-07-27 | Code ▽ | Embed ▽ | No License
1


Thanks to your help, I implemented the fixed code to my WIP game. However it works so weird now...

  1. When the camera follows player (cam_mode = "move"), it appears so much jaggy
  2. After some transitions, the game itself becomes too much slower
  3. When player goes into wide/tall room, camx and camy will be top left of the room despite player is in bottom

I think 1 and 2 is related to 60fps setting and I'm ready to give that up.
And as for 3, I'm seeking the cause and solution...


Cart #gigetiyoja-0 | 2025-07-28 | Code ▽ | Embed ▽ | No License

  • Jaggy player and UI is fixed.
  • Camera moving to top left corner is fixed by changing to other code.
  • Game becomes too slow is not fixed yet...

The estimated cause of slowdown is "map() is too heavy so should be limited"
or "get_current_room() is done in every frame". How do you think?

It seems the slowdown happens when room.x and room.y are both larger than 0 (= either one is 0 will have no issue).


1

The first thing to notice is that performance gets worse when the camera has moved down or right (and even worse if it has moved both), even in rooms where the camera is static, but gets better if you move closer to the top of the map. This suggests that something is doing more work when camx or camy increases.

Turns out this loop in draw_game() is not doing what you want:

 for x=camx/8,camx+128/8 do
  for y=camy/8,camy+128/8 do
   m=mget(x,y)
   if m==74 or m==73 then
    if alert!=0 then
     spr(33,x*8,y*8)
    end
   end
  end
 end

In camx+128/8 the division takes precedence over the addition, and you need to write it as (camx+128)/8. Otherwise, let's say you've scrolled three screens to the right and camx==384, the loop goes from 48 to 400 and is executed 352 times instead of the intended 16 times.


Cart #kogenamapo-0 | 2025-07-28 | Code ▽ | Embed ▽ | No License


Yo it worked!!
Thank you so much for your advice!

That was a fail at entry-level...



[Please log in to post a comment]