Jump to content

Ttexture and DrawImage


AggrorJorn
 Share

Recommended Posts

Hi,

 

I'm trying to load an image on screen when the player is very close to a certain object.

 

I'm trying the following to achieve this:


TTexture hand = LoadTexture("abstract::hand.dds")
DrawImage(hand, MouseX(), MouseY(), 20, 20 )

 

I get the following error message:

 

'=' expected near 'hand'.

 

According to the wiki, I'm using the commands correctly.

 

 

Who can tell me whats going wrong here?

  • Upvote 1
Link to comment
Share on other sites

Hi,

 

I'm trying to load an image on screen when the player is very close to a certain object.

 

I'm trying the following to achieve this:


TTexture hand = LoadTexture("abstract::hand.dds")
DrawImage(hand, MouseX(), MouseY(), 20, 20 )

 

I get the following error message:

 

'=' expected near 'hand'.

 

According to the wiki, I'm using the commands correctly.

 

 

Who can tell me whats going wrong here?

 

 

dont know if this will work but try:

hand = LoadTexture("abstract::hand.dds")
DrawImage(hand, MouseX(), MouseY(), 20, 20 )

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

dont know if this will work but try:

hand = LoadTexture("abstract::hand.dds")
DrawImage(hand, MouseX(), MouseY(), 20, 20 )

 

thx for your suggestion.

 

the good news: no error message.

the bad news: the image doesn't display.

 

I've copied and modified the FPS controller scripts for this. I wonder if it is possible to run the script in the editor and to draw the image on screen when in game modus of the editor.

Link to comment
Share on other sites

thx for your suggestion.

 

the good news: no error message.

the bad news: the image doesn't display.

 

I've copied and modified the FPS controller scripts for this. I wonder if it is possible to run the script in the editor and to draw the image on screen when in game modus of the editor.

 

well i just did it inside the example02.lua... don't forget to add it in the main loop to be rendered each flip... just like drawtext.

--Register abstract path
RegisterAbstractPath("")

--Set graphics mode
if Graphics(1024,768)==0 then
Notify("Failed to set graphics mode.",1)
return
end

--Create framewerk object and set it to a global object so other scripts can access it
fw=CreateFramewerk()
if fw==nil then
Notify("Failed to initialize engine.",1)
return
end
SetGlobalObject("framewerk",fw)

camera=fw.main.camera
camera:SetPositionf(0,0,-2)

light=CreateSpotLight(10)
light:SetRotationf(45,55,0)
light:SetPositionf(5,5,-5)

material=LoadMaterial("abstract::cobblestones.mat")

mesh=CreateCube()
mesh:Paint(material)

ground=CreateCube()
ground:SetScalef(10.0,1.0,10.0)
ground:SetPositionf(0.0,-2.0,0.0)
ground:Paint(material)

light=CreateDirectionalLight()
light:SetRotationf(45,45,45)

hand=LoadTexture("abstract::hand.dds")

while AppTerminate()==0 do

mesh:Turnf(AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5)

fw:Update()
fw:Render()
DrawImage(hand,20,20,200,200)
Flip(0)
end

 

as for doing it in the fpscontroller... let me look.

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

Where are you doing this? In the main loop right before Flip() or in an entity? Remember that 2D needs to be done right before the Flip() statement so really an entity can't handle this right now. I think Josh should create a function that gets called per entity right before the Flip() so it can though. You could probably do this though by adding some code in the fps code. Loop through all entities and if the function Draw2D() exists call it. Then in the entity you want to do this add a Draw2D() function.

Link to comment
Share on other sites

Where are you doing this? In the main loop right before Flip() or in an entity? Remember that 2D needs to be done right before the Flip() statement so really an entity can't handle this right now. I think Josh should create a function that gets called per entity right before the Flip() so it can though. You could probably do this though by adding some code in the fps code. Loop through all entities and if the function Draw2D() exists call it. Then in the entity you want to do this add a Draw2D() function.

 

he said he was doing it in fpscontroller.lua... nothing about an entity.

 

in any case he can do it in that code just like I did in the example02.lua...

 

but aggror, i wouldn't use the mouse positions for your locations of the drawn image... the fpscontroller's "mouse" is always in the center of the screen right? so just draw the hand texture in the center of the screen.

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

Where are you doing this? In the main loop right before Flip() or in an entity? Remember that 2D needs to be done right before the Flip() statement so really an entity can't handle this right now. I think Josh should create a function that gets called per entity right before the Flip() so it can though. You could probably do this though by adding some code in the fps code. Loop through all entities and if the function Draw2D() exists call it. Then in the entity you want to do this add a Draw2D() function.

 

in the main loop.

 

That would be a solution. I think that when I´ll be using more of these drawings, I´ll try something like that.

Link to comment
Share on other sites

small question offtopic. I use the following code centering the image.


--show hand
if KeyDown(KEY_R)==1 then
	local x = GraphicsWidth()/2
	local y = GraphicsHeight()/2

	hand = LoadTexture("abstract::hand.dds")
	DrawImage(hand,x,y,50,50)

end

Is this a correct use of the restiction 'local'?

sure that would work... but i would load the texture before the main loop instead of in the main loop. also you need to offset the 'x' and 'y' by half the size of the image if you expect it to be centered.

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

?

 

the x and y is the upper left hand corner of your texture... if the texture is to be drawn 50x50, then it means you have to make x = (GraphicsWidth()/2)-25 and y = (GraphicsHeight()/2)-25 if you are going to place the texture in the dead center of your screen.

  • 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

thanks for your help

 

no problem, glad i could help. its funny you were asking that question. I added the same thing to the code for the switch just today and i had named my texture the exact same thing for the time being as place art... :)

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

he said he was doing it in fpscontroller.lua... nothing about an entity.

 

in any case he can do it in that code just like I did in the example02.lua...

 

but aggror, i wouldn't use the mouse positions for your locations of the drawn image... the fpscontroller's "mouse" is always in the center of the screen right? so just draw the hand texture in the center of the screen.

 

 

He can, but how much cooler would it be to be able to distribute an entity that you can just drag & drop into the editor and have it do 2D stuff. People could make 2D HUDs and interfaces that we can just drop & drag into the editor. Now that's cool.

Link to comment
Share on other sites

The crappy part currently is that it would require a change to the fps and other "game" scripts. If Josh made each entity call a 2D draw function in the correct place by default then we shouldn't have to require changes to these and it would make it easier. I'll make a feature request for it.

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