graphic code help please

Mods, guides how to use and install mods go right in here.
Post Reply
josh3000
Posts: 10
Joined: 18 Nov 2012, 04:53

Post » 15 Feb 2013, 07:34

Partly inspired by the post asking to make double graphics for boxes, I wanted to add an Old Aperture option to the entities.

Hold your fire, I'm doing most of this on my own.

I've already modded entity.lua and main.lua to tell the game there's another graphic for the gel dispenser. The game doesn't give me any errors on startup, and even recognizes that I want to assign a "graphic" rightclickvalue to the gel dispensers.

The problem is this line in geldispenser.lua:

Code: Select all

function geldispenser:draw()
	if self.dir == "down" then
		love.graphics.draw(geldispenserimg, math.floor((self.cox-xscroll-1)*16*scale), (self.coy-1.5)*16*scale, 0, scale, scale, 0, 0)
	elseif self.dir == "right" then
		love.graphics.draw(geldispenserimg, math.floor((self.cox-xscroll-1)*16*scale), (self.coy+.5)*16*scale, math.pi*1.5, scale, scale, 0, 0)
	elseif self.dir == "left" then
		love.graphics.draw(geldispenserimg, math.floor((self.cox-xscroll+1)*16*scale), (self.coy-1.5)*16*scale, math.pi*0.5, scale, scale, 0, 0)
    end
end
I've tried splitting that into two if-statements, with varying success, but so far I haven't been able to make it recognize there's a second image there. My attempts at modding the code resulted in two of the same default graphics drawn, two of the same alternate graphics drawn, or no graphics at all, just gel spilling out of an invisible...thing.

Obviously, this is less of a problem with self-drawable entities that don't depend on physics code. :D

Any hints or tips are greatly appreciated.

josh3000
Posts: 10
Joined: 18 Nov 2012, 04:53

Post » 19 Feb 2013, 20:17

Bump 'cos of a lack of response for 5 days.

User avatar
Automatik
Posts: 1073
Joined: 20 Jul 2012, 17:54
Contact:

Post » 19 Feb 2013, 20:48

Code: Select all

function geldispenser:draw()
    local img=geldispenserimg
    if rightclickvalue==2 then
        img=secondimage
    end
   if self.dir == "down" then
      love.graphics.draw(img, math.floor((self.cox-xscroll-1)*16*scale), (self.coy-1.5)*16*scale, 0, scale, scale, 0, 0)
   elseif self.dir == "right" then
      love.graphics.draw(img, math.floor((self.cox-xscroll-1)*16*scale), (self.coy+.5)*16*scale, math.pi*1.5, scale, scale, 0, 0)
   elseif self.dir == "left" then
      love.graphics.draw(img, math.floor((self.cox-xscroll+1)*16*scale), (self.coy-1.5)*16*scale, math.pi*0.5, scale, scale, 0, 0)
    end
end

josh3000
Posts: 10
Joined: 18 Nov 2012, 04:53

Post » 21 Feb 2013, 08:47

Cheers, I'll try that. If it's really that easy, then Lua is more intuitive than I thought.

josh3000
Posts: 10
Joined: 18 Nov 2012, 04:53

Post » 22 Feb 2013, 00:38

Huh, that doesn't seem to work either. *stabs myself*

User avatar
Turtle95
Posts: 1246
Joined: 21 Mar 2012, 21:48
Contact:

Post » 22 Feb 2013, 00:48

josh3000 wrote:Huh, that doesn't seem to work either. *stabs myself*
The graphic changes should be during geldispenser:init().

Post Reply