Skip to content

Commit

Permalink
Reset camera between playmodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Oct 25, 2024
1 parent e46488b commit 9a5d813
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
this.isGameModeRunningInEditor = false
SDL2.Mix_HaltMusic()
if this.scene.camera !== nothing && this.scene.camera != C_NULL
#this.scene.camera.target = C_NULL
this.scene.camera.target = C_NULL
end
end

Expand Down
7 changes: 6 additions & 1 deletion src/editor/JulGameEditor/Editor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ module Editor
playMode = !playMode
if playMode
startTime[] = SDL2.SDL_GetTicks()

# Animate the text in the window title
SDL2.SDL_SetWindowTitle(window, "PLAYING $(windowTitle) - $(currentSelectedProjectPath[])")
end
Expand All @@ -253,6 +253,7 @@ module Editor
if playMode != wasPlaying && currentSceneMain !== nothing
if playMode
JulGame.MainLoop.start_game_in_editor(currentSceneMain, currentSelectedProjectPath[])
currentSceneMain.scene.camera = gameCamera
elseif !playMode
JulGame.MainLoop.stop_game_in_editor(currentSceneMain)
JulGame.change_scene(String(currentSceneName))
Expand Down Expand Up @@ -509,6 +510,10 @@ module Editor
#region Input
try
if currentSceneMain !== nothing
if currentSceneMain.scene.camera != gameCamera
gameCamera = currentSceneMain.scene.camera
end

if JulGame.InputModule.get_button_held_down(currentSceneMain.input, "LCTRL") && JulGame.InputModule.get_button_pressed(currentSceneMain.input, "S")
@info string("Saving scene")
events["Save"]()
Expand Down
12 changes: 11 additions & 1 deletion src/engine/Camera/Camera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module CameraModule
SDL2.SDL_SetRenderDrawColor(Renderer, this.backgroundColor[1], this.backgroundColor[2], this.backgroundColor[3], this.backgroundColor[4]);
SDL2.SDL_RenderFillRectF(Renderer, Ref(SDL2.SDL_FRect(this.windowPos.x, this.windowPos.y, this.size.x, this.size.y)))
SDL2.SDL_SetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, rgba.r[], rgba.g[], rgba.b[], rgba.a[]);

center = Vector2f(this.size.x/SCALE_UNITS/2, this.size.y/SCALE_UNITS/2)
if this.target !== nothing && newPosition === nothing && this.target !== C_NULL && newPosition !== C_NULL
targetPos = this.target.position
Expand All @@ -51,4 +51,14 @@ module CameraModule
end
this.position = newPosition
end

# making set property observable
function Base.setproperty!(this::Camera, s::Symbol, x)
@debug("setting camera property $(s) to: $(x)")
try
setfield!(this, s, x)
catch e
println(e)
end
end
end

0 comments on commit 9a5d813

Please sign in to comment.