I tried but it doesnât work I have a script error on set_projection function
and lerp function.
Iâve copied the default.render et default.render_script to another place and renamed them as custom.*
Then Iâve changed the render in my game.project to custom.render.
Here is my collection:
My project contains 3 screens : 1 Main menu, 1 Levels menu and 1 Game screen (where the player plays )
My camera is only present on my Game screen and follows the player
Hereâs my camera.script:
screen_width = tonumber(sys.get_config("display.width")) screen_height = tonumber(sys.get_config("display.height")) function init() msg.post("#camera", "acquire_camera_focus") end function on_message(self, message_id, message, sender) if message_id == hash("follow") then local pos_x = message.position.x - (screen_width/ 2) if pos_x <= 0 then pos_x = 0 elseif pos_x >= screen_width then pos_x = screen_width end local pos_y = message.position.y - (screen_height / 2) if pos_y <= 0 then pos_y = 0 elseif pos_y >= screen_height then pos_y = screen_height end go.set_position(vmath.vector3(pos_x, pos_y, 0)) end end
My player.script just send a message âfollowâ to the camera.script to make it follow.
Hereâs my custom.render_script:
function init(self) self.tile_pred = render.predicate({"tile"}) self.gui_pred = render.predicate({"gui"}) self.text_pred = render.predicate({"text"}) self.particle_pred = render.predicate({"particle"}) self.clear_color = vmath.vector4(0, 0, 0, 0) self.clear_color.x = sys.get_config("render.clear_color_red", 0) self.clear_color.y = sys.get_config("render.clear_color_green", 0) self.clear_color.z = sys.get_config("render.clear_color_blue", 0) self.clear_color.w = sys.get_config("render.clear_color_alpha", 0) self.view = vmath.matrix4() end function update(self) render.set_depth_mask(true) render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0}) render.set_viewport(0, 0, render.get_window_width(), render.get_window_height()) render.set_view(self.view) render.set_depth_mask(false) render.disable_state(render.STATE_DEPTH_TEST) render.disable_state(render.STATE_STENCIL_TEST) render.enable_state(render.STATE_BLEND) render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) render.disable_state(render.STATE_CULL_FACE) render.set_projection(self.projection) render.draw(self.tile_pred) render.draw(self.particle_pred) render.draw_debug3d() render.set_view(vmath.matrix4()) render.set_projection(self.projection) render.enable_state(render.STATE_STENCIL_TEST) render.draw(self.gui_pred) render.draw(self.text_pred) render.disable_state(render.STATE_STENCIL_TEST) render.set_depth_mask(false) render.draw_debug2d() end function on_message(self, message_id, message) if message_id == hash("clear_color") then self.clear_color = message.color elseif message_id == hash("set_view_projection") then self.view = message.view self.projection = message.projection end end