Jump to content

Remove a scene?


gordonramp
 Share

Recommended Posts

ClearWorld(fw.background.world);
ClearWorld(fw.main.world);
ClearWorld(fw.transparency.world);

or

fw.Free();
fw=CreateFramework();
SetGlobalObject("fw",fw);

This is just theoretical code, hasn't been tested :)

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

if KeyHit(KEY_F)==1 then 
FreeFramework(fw)
fw=CreateFramework()
SetGlobalObject("fw",fw)        
scene=LoadScene("Maps/newscene.sbx")

Using the fpscontroller.lua code..

This deletes the old scene and loads the new. I have mouselook but seem to be stuck under the new scene with no movement.

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

if KeyHit(KEY_F)==1 then 
FreeFramework(fw)
fw=CreateFramework()
SetGlobalObject("fw",fw)        
scene=LoadScene("Maps/newscene.sbx")

Using the fpscontroller.lua code..

This deletes the old scene and loads the new. I have mouselook but seem to be stuck under the new scene with no movement.

I had the same problem a while ago. The level loading worked good but the character controls seemed all to stop working. instead of freeing the entire world you can make every object member of group. The character controls are then defined outside the group and wont be removed.

 

scene = LoadScene(test.sbx)
group1=CreateGroup()
SetEntityGroup(scene,group1)

I don't know if this code works with LUA, I can't find it directly.

Link to comment
Share on other sites

Aggror,

That may be a solution but I'm currently unable to implement it within the Framework. I've tried all sorts of things. Like I said, the old scene removes and the new scene loads but but I'm stuck underneath it without movement.

 

VicToMeyeZR,

No change when I flip it.

:)

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Wouldn't you need to set your character controller position to make sure it starts at the right spot in the new scene? If you are stuck underneath the new scene, call a SetPosition() once on the controller to a point where you will be above the scene and when you fall you land on the ground or something in your scene. If you are below your scene you should be falling and any movement would probably look like you aren't moving at all.

Link to comment
Share on other sites

Rick,

When I try to reset the controller with

controller:SetPosition(Vec3(-20,1,-5))

I get an 'Access Violation'.

 

Aggror,

If I place that code within the main loop, nothing happens at all.

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Thanks guys, no improvement, I get the distinct impression that I'm not structuring the code correctly. This is just the sort of topic that really needs a tutorial, changing scenes is basic to any game. :rolleyes:

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Before freeing the world store the controllers data (position rotation ect.) and re-create in the new world?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

May also be a good idea to use a type of entity for each world that will tell your scene manager what the default original position is for each scene. This way you can accurately place the player in those locations. Really depends on what you plan with the multiple scenes but I would do what Marley suggested but changing the controller position to the new "entity_playerstart" location in the new scene once it's loaded.

Link to comment
Share on other sites

Aggror,

Ok, here is the basic Framework fp code that I am building on. It's on this code that I am trying lots of variations.. you should be able to load any map into it.. Note that the first scene is deleted and the new one loaded at the bottom of the main loop.

 

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")

function round(num, idp)        
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
BLEND_NONE=0
BLEND_ALPHA=1

if fw==nil then --we are not in Editor        
RegisterAbstractPath("")        
Graphics(1680,1050)        
fw=CreateFramework()        
scene=LoadScene("Maps/terrain_base.sbx")        
scene:SetCollisionType(COLLISION_SCENE)        
TFilter(1)        
AFilter(4)        
standalone=1
end

dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

--Create a player controller
controller=CreateController(1.8,0.45,0.25,45)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetMass(10)
if standalone==1 then        
controller:SetPosition(Vec3(-20,1,-5))
else        
controller:SetPosition(fw.main.camera.position)
end
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y-110
HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

local camera = fw.main.camera

--position
function DrawHUD(contr)        
SetBlend(BLEND_ALPHA)        
DrawText("position: "..round(contr.position.x,1)..","..round(contr.position.y,1)..","..round(contr.position.z,1),1,FontHeight()*1)        
--DrawText("rot: "..round(contr.rotation.x,3)..","..round(contr.rotation.y,3)..","..round(contr.rotation.z,3),1,FontHeight()*6)        
SetBlend(BLEND_NONE)
end

--main function
while KeyHit(KEY_ESCAPE)==0 do        
jump=KeyHit(KEY_SPACE)*6.0        
if controller:IsAirborne()==1 then jump=0 end        
local time = AppTime()/3200.0        
local frame = time*(179.0-96.0)+96.0        
frame=Clamp( frame, 96, 179 )        

--Camera look        
gx=Round(GraphicsWidth()/2)        
gy=Round(GraphicsHeight()/2)        
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
MoveMouse(gx,gy)        
camerapitch=camerapitch+dy        
camerayaw=camerayaw-dx        
camerapitch=math.min(camerapitch,90)        
camerapitch=math.max(camerapitch,-89.99)       
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        
movespeed=4        
movesmoothing=10        
if controller:IsAirborne()==1 then                
movesmoothing=200        
end 

--Player movement        
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)        
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)        

--Update controller        
controller:Update(camerayaw,move,strafe,jump,40,10)        
fw:Update()        

--Position camera        
camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)        
time=AppTime()        

fw:Render()

DrawHUD(controller) 

--new Framework---------------------------------------------------------------------------------------------------

if KeyHit(KEY_F)==1 then 
FreeFramework(fw)
fw=CreateFramework()
SetGlobalObject("fw",fw)        
scene=LoadScene("Maps/terrain_base2.sbx")
end

------------------------------------------------------------------------------------------------------------------
Flip(0)
end
controller:Free()

ShowMouse()

 

Yes, I have attempted any of the suggestions on this thread.

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

You need to reset the values of the camera variables (camerapitch, camerayaw,and camera) and create a new controller. You are only calling them in the beginning and then you are freeing the frame work then never initializing the values again. Easiest is to just make a function out of the controller creation with these variables included and then call them where you are setting the initial controller and then inside the main loop's if-statement when you are loading a new scene.

 

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")

function round(num, idp)        
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function playercreation() --Function to create a player controller and set camera variables
controller=CreateController(1.8,0.45,0.25,45)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetMass(10)
if standalone==1 then        
controller:SetPosition(Vec3(-20,1,-5))
else        
controller:SetPosition(fw.main.camera.position)
end
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y-110
camera = fw.main.camera
end

BLEND_NONE=0
BLEND_ALPHA=1

if fw==nil then --we are not in Editor        
RegisterAbstractPath("")        
Graphics(1680,1050)        
fw=CreateFramework()        
scene=LoadScene("Maps/terrain_base.sbx")        
scene:SetCollisionType(COLLISION_SCENE)        
TFilter(1)        
AFilter(4)        
standalone=1
end

dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

playercreation()--Call the controller function


HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)



--position
function DrawHUD(contr)        
SetBlend(BLEND_ALPHA)        
DrawText("position: "..round(contr.position.x,1)..","..round(contr.position.y,1)..","..round(contr.position.z,1),1,FontHeight()*1)        
--DrawText("rot: "..round(contr.rotation.x,3)..","..round(contr.rotation.y,3)..","..round(contr.rotation.z,3),1,FontHeight()*6)        
SetBlend(BLEND_NONE)
end

--main function
while KeyHit(KEY_ESCAPE)==0 do        
jump=KeyHit(KEY_SPACE)*6.0        
if controller:IsAirborne()==1 then jump=0 end        
local time = AppTime()/3200.0        
local frame = time*(179.0-96.0)+96.0        
frame=Clamp( frame, 96, 179 )        

--Camera look        
gx=Round(GraphicsWidth()/2)        
gy=Round(GraphicsHeight()/2)        
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
MoveMouse(gx,gy)        
camerapitch=camerapitch+dy        
camerayaw=camerayaw-dx        
camerapitch=math.min(camerapitch,90)        
camerapitch=math.max(camerapitch,-89.99)       
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        
movespeed=4        
movesmoothing=10        
if controller:IsAirborne()==1 then                
movesmoothing=200        
end 

--Player movement        
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)        
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)        

--Update controller        
controller:Update(camerayaw,move,strafe,jump,40,10)        
fw:Update()        

--Position camera        
camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)        
time=AppTime()        

fw:Render()

DrawHUD(controller) 

--new Framework---------------------------------------------------------------------------------------------------

if KeyHit(KEY_F)==1 then 
FreeFramework(fw)
fw=CreateFramework()
SetGlobalObject("fw",fw)        
scene=LoadScene("Maps/terrain_base2.sbx")
playercreation()-- call the controller function again to create new controller and camera variables
end

------------------------------------------------------------------------------------------------------------------
Flip(0)
end
controller:Free()

ShowMouse()

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...