Love Remove Image command Request

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.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Love Remove Image command Request

Post by weilies »

i have drawn 3 images, code below

Code: Select all

function love.draw()

		
	-- draw image
	love.graphics.draw(arrow, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
	love.graphics.draw(arrow, 200, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
	love.graphics.draw(arrow, 300, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)

end
input handler

Code: Select all

-- key press 'c' to clear my image
love.graphics.clear ( )

but i realized that next second it will redraw 3 images due to the draw always callback
My question is how can i click on "c" and only the second image above is remove and other remain unchange?
What is the proper remove-image command to use? love.graphics.clear ( ) doesnt look right for me coz it will always clear all my object on screen


Thanks again for all the help!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Love Remove Image command Request

Post by bartbes »

Instead of removing it, you need to stop drawing it, so you probably want an if in your love.draw.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Love Remove Image command Request

Post by weilies »

bartbes wrote:Instead of removing it, you need to stop drawing it, so you probably want an if in your love.draw.
any sample? isn't that better for every image object created, will be assign to a variable

Eg. logic

Code: Select all

myObjRef[1] =  love.graphics.draw(image, imgx, imgy)

love.graphics.stopDraw(myObjRef[1] )
Let say if i am creating a Space Invader game, how hard for me to create a "stop draw when shoot collide" logic
or any actual working sample out there for love engine?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love Remove Image command Request

Post by kikito »

You have not understood the fundamentals yet. Please read the next two points carefully:
  • love.draw is a function that gets called once per frame
  • Before calling it, LÖVE erases the screen completely
What bartbes says is that the only thing you have to do in order to 'stop drawing' your images is to literally stop calling love.graphics.draw inside love.draw. You need to do the equivalent to this:

Code: Select all

 function love.draw()
  if condition_for_drawing_arrow then   
     love.graphics.draw(arrow, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
     love.graphics.draw(arrow, 200, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
     love.graphics.draw(arrow, 300, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
  end
end
On that sample, condition_for_drawing_arrow is an expression that you have to build. A good way to start would be to create some global variables, update them on love.update, and use them on love.draw for conditionally drawing stuff.
When I write def I mean function.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Love Remove Image command Request

Post by weilies »

hi kikito,

Thanks for the reply and yes, i am still new bird who in love

i jz figure out this yday night
* love.draw is a function that gets called once per frame
i jz know this after reading this post
* Before calling it, L?VE erases the screen completely

regarding the function below

Code: Select all

    function love.draw()
      if condition_for_drawing_arrow then   
         love.graphics.draw(arrow, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
         love.graphics.draw(arrow, 200, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
         love.graphics.draw(arrow, 300, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
      end
    end
i notice this is the way to draw/remove after i know the role below (and reason i open this thread is to ask for any friendly alternative solution)
* love.draw is a function that gets called once per frame

i actually come from other game programming background,
Question for the creator of love (no offence)
since we are using command below to create an object on screen

Code: Select all

	love.graphics.draw(arrow, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
isn't that better to store the object to a variable (as an object), so that later can use object.scaleX, object.getPostX, object.RemoveMe
	fish = love.graphics.draw(fish_sprite, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)
	fish_food = love.graphics.draw(food_sprite, 100, 200, math.rad(arrow_rotate_angle), 1, 1, 75, 200)

then when fish fish collide with fish_food
we jz write fish_food.RemoveMe
instead of saying, "if fishfood_not_yet_eaten" logic
i mean, if my idea doesn't work in love, i will follow kikito's approach
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Love Remove Image command Request

Post by nevon »

weilies wrote:i mean, if my idea doesn't work in love, i will follow kikito's approach
You can most certainly do that. One common approach is using object orientation and give each object its own draw method.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love Remove Image command Request

Post by vrld »

You don't seem to understand correctly.
love.graphics.draw does exactly what the name suggests: It draw to the screen. It does not put an object there. It just draws.
If you don't want something on the screen, you must not draw it.

The other game engine you used probably used a some sort of scene management, where you actually have objects that get drawn for you. Love is more low-level than this.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Love Remove Image command Request

Post by zac352 »

o_O Why is it taking so long for you to understand?
Love works per frame.
If something is supposed to appear on screen, you draw it. If it isn't, you don't draw it.... :roll:
Hello, I am not dead.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Love Remove Image command Request

Post by bartbes »

I'd like to note that you should totally ignore zac352.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Love Remove Image command Request

Post by zac352 »

bartbes wrote:I'd like to note that you should totally ignore zac352.
That's probably true.
Hello, I am not dead.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests