Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Fri Feb 28, 2020 8:23 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Sprite questions
PostPosted: Thu Feb 25, 2016 9:29 pm 
Offline

Joined: Wed Nov 25, 2015 4:56 pm
Posts: 24
Is there a way to change an entire sprite's brightness or opacity so that you can make them fade in or out.

Example, make a logo fade in and then out again?


Also, is there an easy way with directx to apply special filter layers to a sprite?

Example, applying a brightening filter so that a figure sprite standing near a light source will brighten the pixels of the figure sprite only in the areas highlighted on the filter layer.
Also the same sort of thing but for shadows. So a filter that only darkens certain pixels of a sprite.

Sprite Brightening Filter
+--------+ +--------+
|.......**.......| |.......**......|
|.......**.......| |................|
|.......**.......| |................|
+--------+ +--------+

In above diagram the brightening filter will brighten the top two pixels of the sprite. The amount of brightness also needs to be adjustable.

I remember using a similar technique programming on my Amiga 1200 :D


Thanks :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Sprite questions
PostPosted: Fri Feb 26, 2016 12:45 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 554
KDK1976 wrote:
Is there a way to change an entire sprite's brightness or opacity so that you can make them fade in or out.
Example, make a logo fade in and then out again?

The Particle Demo http://www.programming2dgames.com/bonus.htm has a logo that fades out. The update function adjusts the menuAlpha variable.
Code:
void ParticleDemo::update()
{
    if (menuOn)
    {
        if(menuDisplay > 0)                 // if menu display timer > 0
            menuDisplay -= frameTime;       // subtract elapsed time from timer
        else
        {
            menuAlpha -= frameTime*MENU_FADE_RATE;  // fade out menu
            if(menuAlpha < 0)
                menuOn = false;             // do not display
        }
    }

The menuAlpha variable is used in the render() function to draw the logo with varying amounts of transparency.
void ParticleDemo::render() function:
Code:
    if(menuOn)
        menu.draw(SETCOLOR_ARGB(static_cast<int>(menuAlpha),255,255,255));

KDK1976 wrote:
Also, is there an easy way with directx to apply special filter layers to a sprite?
The SpaceWar example draws a shield around the space ships using the following code:
Code:
        if(shieldOn)
            // draw shield using colorFilter 50% alpha
            shield.draw(spriteData, graphicsNS::ALPHA50 & colorFilter);
The shield is drawn semi-transparent to allow the ship to remain visible. The colorFilter is used to give the shield a color that matches the ship. A technique similar to this shield draw could be used to give the effect you want. Draw a semi-transparent black image on top of the sprite to make part of it darker or lighter. A larger alpha value will make the sprite darker and a smaller alpha value will make the sprite brighter.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
 Post subject: Re: Sprite questions
PostPosted: Sat Feb 27, 2016 8:52 am 
Offline

Joined: Wed Nov 25, 2015 4:56 pm
Posts: 24
That's excellent thanks :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group