Jump to content

Sprite position


diedir
 Share

Go to solution Solved by diedir,

Recommended Posts

Hello, me again.. i try to position a sprite created for head up display over a scene, but can't move the display where i want

here the code i used :

--Get the displays
local displays = GetDisplays()

--Create window
local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1])

--Create framebuffer
local framebuffer = CreateFramebuffer(window)

--Create world
local world = CreateWorld()

--env map
local specmap = LoadTexture("./Materials/Environment/Default/specular.dds")
local diffmap = LoadTexture("./Materials/Environment/Default/diffuse.dds")
world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND)
world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR)
world:SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE)

--[[load map
local mapname = "Maps/scene1.ultra"
local cl = CommandLine()
if type(cl["map"]) == "string" then mapname = cl["map"] end
local scene = LoadMap(world, mapname)
--]]

--Create light
local light = CreateBoxLight(world)
light:SetRange(-10, 10)
light:SetArea(15, 15)
light:SetRotation(45, 35, 0)
light:SetColor(2)

--Load a font
local font = LoadFont("Fonts/arial.ttf")
local fontsize = 36

-- Create sprite
local sprite = CreateSprite(world, font,"HEY YOU !",fontsize) 
sprite:SetColor(1, 1, 1, 1)
sprite:SetPosition(0,-50, 0)

-- Create a camera
local camera = CreateCamera(world,PROJECTION_PERSPECTIVE)
camera:SetClearColor(0.125)
camera:SetPosition(0, 5, 0)

--Create second camera
local cam2 = CreateCamera(world,PROJECTION_ORTHOGRAPHIC)
cam2:SetPosition(0, 0, 0)
cam2:SetClearMode(CLEAR_DEPTH)

--Camera controls to look around
require 'Components/Player/CameraControls'
camera:AddComponent(CameraControls)

--main loop
while not window:KeyDown(KEY_ESCAPE) do 
    world:Update()
    world:Render(framebuffer)
end

Thank you for helping

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

You're not setting your cam2 or your sprite to a new render layer.

Not much of a Lua user, but try this.

--Get the displays
local displays = GetDisplays()

--Create window
local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1])

--Create framebuffer
local framebuffer = CreateFramebuffer(window)

--Create world
local world = CreateWorld()

--env map
local specmap = LoadTexture("./Materials/Environment/Default/specular.dds")
local diffmap = LoadTexture("./Materials/Environment/Default/diffuse.dds")
world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND)
world:SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR)
world:SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE)

--[[load map
local mapname = "Maps/scene1.ultra"
local cl = CommandLine()
if type(cl["map"]) == "string" then mapname = cl["map"] end
local scene = LoadMap(world, mapname)
--]]

--Create light
local light = CreateBoxLight(world)
light:SetRange(-10, 10)
light:SetArea(15, 15)
light:SetRotation(45, 35, 0)
light:SetColor(2)

--Load a font
local font = LoadFont("Fonts/arial.ttf")
local fontsize = 36


-- Create a camera
local camera = CreateCamera(world,PROJECTION_PERSPECTIVE)
camera:SetClearColor(0.125)
camera:SetPosition(0, 5, 0)

--Create second camera
local cam2 = CreateCamera(world,PROJECTION_ORTHOGRAPHIC)
cam2:SetPosition(0, 0, 0)
cam2:SetClearMode(CLEAR_DEPTH)
cam2:SetRenderLayers(1)

-- Create sprite
local sprite = CreateSprite(world, font,"HEY YOU !",fontsize) 
sprite:SetColor(1, 1, 1, 1)
sprite:SetPosition(0, 0, 0)
sprite:SetRenderLayers(1)

--Camera controls to look around
require 'Components/Player/CameraControls'
camera:AddComponent(CameraControls)

--main loop
while not window:KeyDown(KEY_ESCAPE) do 
    world:Update()
    world:Render(framebuffer)
end

This should spawn the sprite in the center of the screen.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Move the camera to the bottom edge of the framebuffer. 0,0 should be the top left of the screen. Then you can use the size of the framebuffer to position the sprite wherever you want like if you were using the Interface class. 

local size = framebuffer:GetSize()
cam2:SetPosition(size.x * 0.5, size.y * 0.5f)

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • Solution

Ok i got it,

simply by positionning the sprite in 2D coords like -400,300

x negative on the left side, x positve on the right and y positive on top side and negative in the bottom

0,0 is the center of the window

thank you Reepblue

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

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...