[5.21 -> 5.31] Entity is inactive
Posted: Tue Nov 04, 2014 11:34 pm
■ Snippet codeMoveEntity () should wake up the entity.
■ if i change the codebythe entity moves.
Code: Select all
EnableExplicit
Enumeration
#Mainform
EndEnumeration
Global WWIdth, WHeight, Window, Event
Global Camera, Texture, Material, Mesh, Entity
Global Ground, Player, PlayerSpeed.f
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()
OpenWindow(#Mainform,0,0, 0, 0, "", #PB_Window_SystemMenu | #PB_Window_Maximize)
WWidth = WindowWidth(#Mainform, #PB_Window_InnerCoordinate)
WHeight = WindowHeight(#Mainform, #PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(#Mainform),0,0,WWIdth,WHeight,0, 0, 0)
KeyboardMode(#PB_Keyboard_International)
;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Additive)
;
; Texture and materialt
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()
Material = CreateMaterial(#PB_Any,TextureID(texture))
;
; Ground
Mesh = CreatePlane(#PB_Any, 20, 20, 3, 6, 6, 6)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 0, 0)
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 2, 0, 1)
;
; Player (A cube=)
Mesh = CreateCube(#PB_Any, 1)
Player = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Player, #PB_Entity_BoxBody, 10,2,2)
;
; Camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(145, 182, 201))
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
If ExamineKeyboard()
If KeyboardPushed (#PB_Key_Escape)
Break
EndIf
EndIf
If KeyboardPushed (#PB_Key_Left)
RotateEntity(Player, 0, 1.5, 0, #PB_Relative)
ElseIf KeyboardPushed (#PB_Key_Right)
RotateEntity(Player, 0, -1.5, 0, #PB_Relative)
EndIf
If KeyboardPushed (#PB_Key_Up)
PlayerSpeed = 1.5
ElseIf KeyboardPushed (#PB_Key_Down)
PlayerSpeed = - 1.5
Else
PlayerSpeed = 0
EndIf
;The bug
If PlayerSpeed <> 0
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
EndIf
;CamearaFollow (Since PB 5.20)
CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 3, 6, 0.05, 0.05, #True)
; Rendering
RenderWorld(80)
FlipBuffers()
ForEver
■ if i change the code
Code: Select all
If PlayerSpeed <> 0.0
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
EndIf
Code: Select all
If PlayerSpeed <> 0.0
DisableEntityBody(Player, #False)
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
EndIf