Subj : Re: Transparency when using frames/sprites
To   : MCMLXXIX
From : Kirkman
Date : Fri Jun 20 2014 02:29 pm

> solution 2: iterate frame.data (this returns the entire graphic you loaded
> in) once, outside of the user input loop. you can do this once, immediately
> after loding the graphic in, so you arent doing it every single time it
> runs through your loop.


So, the second solution definitely sounds better, since I only need to do it
once. I wrote up some code, but the results I'm getting are the same as
before. The sprite looks great in it's initial orientation, but when I move it
a different direction, the mask doesn't match the new orientation.

Using a little debugger function, I see that the maskFrame function is indeed
iterating over all the characters in the entire sprite. So I'm not sure why
this isn't working.

Here's my revised code:

function maskFrame(theFrame) {
   var x, y, theArray, theChar;
   for (x=0; x<theFrame.data.length; x++) {
       theArray = theFrame.data[x];
       for (y=0; y<theArray.length; y++) {
           theChar = theFrame.data[x][y];
           if (theChar.ch == ' ' && theChar.attr < 15) {
               theFrame.data[x][y].ch = undefined;
               theFrame.data[x][y].attr = undefined;
           }
       }
   }
}

function gamePlay() {
   player.sprite = new Sprite.Profile("boy", mapFrame, 1, 1, 'e', 'normal');
   maskFrame(player.sprite.frame);
   player.sprite.frame.draw();
   var userInput = '';
   while( ascii(userInput) != 13 ) {
       userInput = console.getkey(K_UPPER | K_NOCRLF);
       player.sprite.getcmd(userInput);
       Sprite.cycle();
       mapFrame.cycle();
   }
}


--Josh

////--------------------------------------------------
BiC -=- http://breakintochat.com -=- bbs wiki and blog

---
� Synchronet