Jump to content

Hide or Delete Image (context) command in LUA??


Russell
 Share

Recommended Posts

Hi there...

I'm new using LUA creating my own scripts from scratch.

And this is a question that is driving me crazy.

I want SHOW/HIDE a image centered on screen after USE an object ingame. With this code I have managed to show the image without problems:

-----------
Script.HudTextura=""

local ScriptActivo="Yes"
local ShowImage="No"

function Script:Use()
    if self.enabled then
        ShowImage="Yes"
    else
        ShowImage="No"
    end        
end

function Script:PostRender(context)
    if ShowImage=="Yes" then
        context:SetBlendMode(Blend.Alpha)
        texture = Texture:Load("Materials/MisTexturas/"..self.HudTextura..".tex")
        context:DrawImage(texture,context:GetWidth()/2-texture:GetWidth()/2,context:GetHeight()/2-texture:GetHeight()/2,texture:GetWidth(),texture:GetHeight())
    end
end

-----------

But I don't know how hide or erase it after that.

I have searched forum and Google, but the answers i've found have not helped me. I'm not able to find any command to hide or delete the image after displaying it.

Can anybody help me?

I'm not using FlowGUI or FlipHook because i want learn LUA from beginning creating my own simple scripts.

Thank you very much!!

Link to comment
Share on other sites

One thing that caught my eye is you are loading a texture in Post Render, which is called every frame. Load the texture in the start function. Otherwise, that's ok.

It seems ShowImage is never being set to "No". I also recommend making that value a Boolean member of  the script. (Ie: self.showimage)

  • Thanks 1

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

Thank you very much for the answer... I've putted "LOAD Texture" commands in the Start Function.

Anyway, after hours of battle with LUA, finally i've solved my problem loading an empty-small texture of 32x32 on Start Function too...

Now my code works fine for me like this:

---------------------
Script.HudTexture=""
local ScriptActivo="Yes"
local ShowedImagen="No"

function Script:Start()
    self.enabled=true
    texture = Texture:Load("Materials/MyTextures/"..self.HudTexture..".tex")
    textureEmpty = Texture:Load("Materials/MyTextures/Empty.tex")
end

function Script:Use()
    if ShowedImagen=="Yes" then
        ShowedImagen="No"
    else
        ShowedImagen="Yes"
    end
end

function Script:PostRender(context)
    if ShowedImagen=="Yes" then
        context:SetBlendMode(Blend.Alpha)
        context:DrawImage(texture,context:GetWidth()/2-texture:GetWidth()/2,context:GetHeight()/2-texture:GetHeight()/2,texture:GetWidth(),texture:GetHeight())
    end
    if ShowedImagen=="No" then
        context:SetBlendMode(Blend.Alpha)
        context:DrawImage(textureEmpty,context:GetWidth()/2-textureEmpty:GetWidth()/2,context:GetHeight()/2-textureEmpty:GetHeight()/2,textureEmpty:GetWidth(),textureEmpty:GetHeight())
    end
end

---------------------

I don't know if this solution is the best, but It works fine for me.

With my little knowledge in LUA, I am quite satisfied with the result.

 

Thank you very much!! ?

Link to comment
Share on other sites

Ok, now with this code the problem is...

If i put 2 or more images on the level with this code, when i active one of them and activate another one with the same code, 2 images stay together on screen.

Is there any way to clear the activated image before show a second one???

If i use context.clear() my screen becomes white.

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