gordonramp Posted January 13, 2010 Share Posted January 13, 2010 I'm attempting to change a scene by loading a new one with LoadScene() and this seems to work but I can't find a command to remove the old scene. Is there one? Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
Canardia Posted January 13, 2010 Share Posted January 13, 2010 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 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
gordonramp Posted January 13, 2010 Author Share Posted January 13, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 14, 2010 Share Posted January 14, 2010 what if you put the : Flip(0) inside your if statement? Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
gordonramp Posted January 14, 2010 Author Share Posted January 14, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 14, 2010 Share Posted January 14, 2010 I'll give this a try myself. I need to find out how to do this as well in lua. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 14, 2010 Share Posted January 14, 2010 try using this: if KeyHit(KEY_1)==1 then FreeWorld(fw.main.world) scene=LoadScene("Maps/1.sbx") end if KeyHit(KEY_2)==1 then FreeWorld(fw.main.world) scene=LoadScene("Maps/2.sbx") end Quote Link to comment Share on other sites More sharing options...
gordonramp Posted January 14, 2010 Author Share Posted January 14, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
Rick Posted January 14, 2010 Share Posted January 14, 2010 OK, then I'm guessing the controller was created in the current world. When you free the world it is freeing the controller. Which means you have no more controller. Recreate the controller after you load the new scene. Quote Link to comment Share on other sites More sharing options...
gordonramp Posted January 15, 2010 Author Share Posted January 15, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 15, 2010 Share Posted January 15, 2010 You can't be far from it. Neither am I, I think. Could you past the code you have where you can switch the scene, but where the control fail? Quote Link to comment Share on other sites More sharing options...
Marleys Ghost Posted January 15, 2010 Share Posted January 15, 2010 Before freeing the world store the controllers data (position rotation ect.) and re-create in the new world? Quote 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 More sharing options...
AggrorJorn Posted January 15, 2010 Share Posted January 15, 2010 Did you try the thing Rick said? with creating a new controller since the old one gets removed? Quote Link to comment Share on other sites More sharing options...
Paul Thomas Posted January 15, 2010 Share Posted January 15, 2010 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. Quote Link to comment Share on other sites More sharing options...
gordonramp Posted January 15, 2010 Author Share Posted January 15, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 15, 2010 Share Posted January 15, 2010 Did you give it a try before you call : fw:Render() Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 15, 2010 Share Posted January 15, 2010 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() 1 Quote 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 More sharing options...
gordonramp Posted January 15, 2010 Author Share Posted January 15, 2010 macklebee to the rescue, Nice, that works. As I thought, it was the way the controller code etc. was structured. Thanks, that's a big help. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
macklebee Posted January 15, 2010 Share Posted January 15, 2010 macklebee to the rescue, Nice, that works. As I thought, it was the way I was structuring the controller code etc.. That's a big help. glad to help... Quote 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 More sharing options...
Recommended Posts
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.