What is wrong with this formula?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

What is wrong with this formula?

Post by Lua Hal »

Code: Select all

function dtr(degrees)
return math.pi*degrees/180
end
function dwr(object,X,Y,rotation,flipx,flipy) --ENUM, number, number, number, bool, bool
if flipx == true then
numx=-1
else
numx=1
end
if flipy == true then
numy=-1
else
numy=1
end
height=love.graphics.getHeight()
width=love.graphics.getHeight()
love.graphics.draw(object,width/2,height/2,dtr(rotation),numx,numy,(width/2)-X,(height/2)-Y) 
end
function love.draw()
p=love.graphics.newImage("Textures\/Sprit1.png")
dwr(p,0,0,0,false,false)
dwr(p,0,16,90,false,true)
dwr(p,16,0,180,true,false)
dwr(p,16,16,270,true,true)
end
Image

They should be compacted in a 32x32 pixel square. D:
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: What is wrong with this formula?

Post by tentus »

First problem: no indentation. Second problem: several function calls in places they should be (especially newImage). Third problem: you used width/2 twice. You don't need it in the offset parameters.

Code: Select all

function dtr(degrees)
	return math.pi*degrees/180
end

function dwr(object,X,Y,rotation,flipx,flipy) --ENUM, number, number, number, bool, bool
	if flipx == true then
		numx=-1
	else
		numx=1
	end
	if flipy == true then
		numy=-1
	else
		numy=1
	end
	love.graphics.draw(object, width/2, height/2, dtr(rotation), numx, numy, X, Y)
end

function love.load()
	p=love.graphics.newImage("sprite.png")
	height=love.graphics.getHeight()
	width=love.graphics.getHeight()
end

function love.draw()
	dwr(p,0,0,0,false,false)
	dwr(p,0,16,90,false,true)
	dwr(p,16,0,180,true,false)
	dwr(p,16,16,270,true,true)
end
Kurosuke needs beta testers
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: What is wrong with this formula?

Post by Lua Hal »

No, I want it to use the normal positioning, not off of the origin.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: What is wrong with this formula?

Post by Robin »

Lua Hal wrote:No, I want it to use the normal positioning, not off of the origin.
You need to offset by the size of the image, not the size of the screen. There were some other bad things in your code tentus didn't fix as well.

Code: Select all

function dwr(object,X,Y,rotation,flipx,flipy) --ENUM, number, number, number, bool, bool
	love.graphics.draw(object, X + width/2, Y + height/2, math.rad(rotation), flipx and -1 or 1, flipy and -1 or 1, width/2, height/2)
end

function love.load()
	p=love.graphics.newImage("sprite.png")
	height=p:getHeight()
	width=p:getHeight()
end

function love.draw()
	dwr(p,0,0,0,false,false)
	dwr(p,0,16,90,false,true)
	dwr(p,16,0,180,true,false)
	dwr(p,16,16,270,true,true)
end
Hope this helps.
Help us help you: attach a .love.
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: What is wrong with this formula?

Post by Lua Hal »

Robin wrote:
Lua Hal wrote:No, I want it to use the normal positioning, not off of the origin.
You need to offset by the size of the image, not the size of the screen. There were some other bad things in your code tentus didn't fix as well.

Code: Select all

function dwr(object,X,Y,rotation,flipx,flipy) --ENUM, number, number, number, bool, bool
	love.graphics.draw(object, X + width/2, Y + height/2, math.rad(rotation), flipx and -1 or 1, flipy and -1 or 1, width/2, height/2)
end

function love.load()
	p=love.graphics.newImage("sprite.png")
	height=p:getHeight()
	width=p:getHeight()
end

function love.draw()
	dwr(p,0,0,0,false,false)
	dwr(p,0,16,90,false,true)
	dwr(p,16,0,180,true,false)
	dwr(p,16,16,270,true,true)
end
Hope this helps.
Thanks a bunch, dude.

+1 karma
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: What is wrong with this formula?

Post by Robin »

Lua Hal wrote:+1 karma
You know you can click that big + sign under my avatar for that, right? ;)
Help us help you: attach a .love.
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: What is wrong with this formula?

Post by Lua Hal »

Robin wrote:
Lua Hal wrote:+1 karma
You know you can click that big + sign under my avatar for that, right? ;)
That's what I did.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 188 guests