How to make an object in game disappear!

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1154 Views - Last Post: 31 January 2012 - 04:21 PM Rate Topic: -----

#1 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

How to make an object in game disappear!

Posted 26 January 2012 - 10:53 AM

Hi All,

I need to make an object disappear in a 2D game, i tried to do it so by replacing its color by
background color as background has uniform color ,but its not good way, as i encountered certain problems.

i think we can disappear an object by just making its alpha component of color zero but that too on happening of
some event , like if a bullet hits a player , he dies and disappears.

I am using SDL and but don't know how to implement what i am thinking...

Is This A Good Question/Topic? 0
  • +

Replies To: How to make an object in game disappear!

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: How to make an object in game disappear!

Posted 26 January 2012 - 11:19 AM

Are you talking about disappear as in "blip - one moment it's there and the next it's gone, or a fade out situation?
Was This Post Helpful? 0
  • +
  • -

#3 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 26 January 2012 - 11:41 AM

View Postmodi123_1, on 26 January 2012 - 11:19 AM, said:

Are you talking about disappear as in "blip - one moment it's there and the next it's gone, or a fade out situation?


i need it to blip, actually i am moving an object , so before moving it to the next position i need to erase its
current instance then draw it at the next position.so initially i was erasing it by coloring it as the background color.
so that it don't show up.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: How to make an object in game disappear!

Posted 26 January 2012 - 11:47 AM

It's been a while since I messed with SDL but isn't there a method like "SDL_FreeSurface(<image's name or object>)" that clears the surface?
Was This Post Helpful? 0
  • +
  • -

#5 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 26 January 2012 - 11:59 AM

there is a function like this but it clears whole surface,i am drawing on one surface, so all of my drawings are on one surface, if i call above method everything will be erased, but i just need to erase that part of the surface , where my object is.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: How to make an object in game disappear!

Posted 26 January 2012 - 12:01 PM

Are you calling that method with the specific image/object name?
Was This Post Helpful? 0
  • +
  • -

#7 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 26 January 2012 - 12:12 PM

firstly i should tell you how i am using the objects..

i have a single "png" in which various objects are there , i clip objects from this png and
draw them over the surface.Now, the whole "png" is itself treated as the surface and our screen as the destination surface.

so for above function to work, i will have to pass it a surface and as i am drawing it on screen
i will have to pass it screen's surface, which will free up my whole screen. am i correct?
Was This Post Helpful? 0
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to make an object in game disappear!

Posted 26 January 2012 - 01:25 PM

You have to render to the whole surface again without the object you wish rendered to 'erase' it.

This post has been edited by ButchDean: 26 January 2012 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#9 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 27 January 2012 - 11:06 AM

hi Butchdean,

do other games follow same approach , as it looks like doing alot , as compared to making just an "object" disappear !!
Was This Post Helpful? 0
  • +
  • -

#10 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to make an object in game disappear!

Posted 27 January 2012 - 11:14 AM

Hi

It really depends on what you're trying to do. From what you've written, for some reason you simply cannot omit rendering the object to make it disappear. I don't know why this isn't an option for you, and depends on how you have coded your game.
Was This Post Helpful? 0
  • +
  • -

#11 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 27 January 2012 - 11:31 AM

i didn't mean i dnt want to render an object in order to make it disappear..
as i have mentioned i am moving an object , say from point A to B , in order to move it to point B , i have to first make disappear at point A and then showing it at point B , i was thinking if i can make its alpha channel zero at the run time..is this approach possible??

This post has been edited by gamazone: 27 January 2012 - 11:38 AM

Was This Post Helpful? 0
  • +
  • -

#12 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to make an object in game disappear!

Posted 27 January 2012 - 11:43 AM

No, you just translate it. What you are proposing will leave you with multiple instances of the same object.
Was This Post Helpful? 0
  • +
  • -

#13 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 27 January 2012 - 10:45 PM

ok, i will be creating exact copy of that object means it will have exact dimensions but its color will be background color,i will replace it with the original object,(initially i had problem with this approach as i was not replacing it with its exact copy )
Would it be fine?
Was This Post Helpful? 0
  • +
  • -

#14 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to make an object in game disappear!

Posted 28 January 2012 - 01:34 PM

No.

The steps actually taken are:

1. Draw entire scene with object in current position.
2. Translate object to new position.
3. Redraw scene with object in new position.

I can't make it any clearer than that.
Was This Post Helpful? 0
  • +
  • -

#15 gamazone  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 44
  • Joined: 05-April 11

Re: How to make an object in game disappear!

Posted 29 January 2012 - 02:26 AM

ok got it!! :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2