Author Topic: "Shadows", arrays questions  (Read 4633 times)

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
"Shadows", arrays questions
« on: Mon, Jul 26, 2010 »
So, I kinda need a lot more help with this than I thought.

My idea was to create a platformer based on using shadows to obscure obstacles and platforms. Then I thought it would be neat to have a negative-ish overlay over a part of the stage and have the player activate a flash light that would reveal that. So I thought, just make the shadows and then turn them white right?

Long story short, after several failure I decided to follow the guys code from the game "I can hold my breath forever!" What happens when I click run, is that the background is white like I want, but my light isn't causing anything to show up. So, here's my code:

Playstate
Code: [Select]
package 
{

import org.flixel.*;
//import flash.geom.Point;

//future sound reference: FlxG.play(SndClass,1,true);
//possible future reference: alpha += FlxG.elapsed/_delay;
public class TutorialBlipping extends FlxState
{
//for tutorial jumping specifics

//Text
//[Embed(source = "pics/blipText2.png")] private var Instructions:Class;

//Environment
//[Embed(source="maps/blipLevel2JumpingTut.txt",mimeType="application/octet-stream")] private var TxtMap:Class;

//Embeds

//Invisible play areas and tools are not needed on basic turorial levels
//Audio
[Embed(source = "noise/SpyChill.mp3")] private var clickSound:Class;
[Embed(source = "noise/HalfTech.mp3")] private var clickSound4:Class;

[Embed(source = "noise/teleportSound.mp3")] private var clickSound2:Class;
//Tiles
[Embed(source = "pics/blipTileset.png")] private var ImgTiles:Class;
[Embed(source = "pics/blipTilesetB.png")] private var ImgTiles2:Class;
[Embed(source = "pics/blipText1.png")] private var Instructions:Class;

//Environment
[Embed(source="maps/blipLevel2JumpingTut.txt",mimeType="application/octet-stream")] private var TxtMap:Class;
//invisible tiles
[Embed(source="maps/blipHiddenLevel1.txt",mimeType="application/octet-stream")] private var TxtMap2:Class;
//[Embed(source = "pics/blipHiddenLevel1scrn.png")] public var _hidden:Class;


//Other game objects
[Embed(source = "pics/blipExitDoor.png")] public var Exit:Class;

//----adding  lights and darks
//Both classes are the same file. But the fed is used for fading.
//And the White is used for obscuring the background.
[Embed(source = "pics/dark.png")] private var ImgWhite:Class;
[Embed(source = "pics/dark.png")] private var ImgFed:Class;

//Since this is the tutorial that teaches players how to "blip"
// or in other words, see the invisible stage, we need to add the light object

[Embed(source = "pics/blipSight.png")] public var eye:Class;
[Embed(source = "pics/blipSight.png")] public var eye2:Class;



[Embed(source = 'pics/Blip.png')] private var ImgPlayer:Class;




//Private and public variables
{
private var title_text:FlxText;
private var _tilemap:FlxTilemap;

//darkness
private var darkness:FlxSprite;
private var darkness_color:uint = 0xffffffff;

//invisible tiles
private var _tilemap2:FlxTilemap;

//adding player and player objects
public var _player:Blip;
public var _eye:Site;
public var _eye2:Site2;
private var _exitDoor:ExitDoor;
private var _vision:Site;
private var _blind:Blind;
private var _blind2:Blind2;
public var _hidden:HiddenLevel;

//adding layer groups
public static var lyrSight:FlxGroup;
//the order is explained at the add section further down below
public static var lyrStage:FlxGroup;
public static var lyrStage2:FlxGroup;
public static var lyrSprites:FlxGroup;
public static var lyrBlind:FlxGroup;
public static var lyrBlind2:FlxGroup;
public static var lyrHidden:FlxGroup;


public static var lyrfadeIn:FlxGroup;
public static var lyrEye:FlxGroup;
public static var lyrEye2:FlxGroup;

//public static var lyrBackdrop:FlxGroup;
//addding a counter for fade in
public var counter:Number = 0;
public var fed:FlxSprite;


}

override public function create():void

{
//counter += FlxG.elapsed;


//Initializing layers

{
//lyrBackdrop = new FlxGroup;

lyrStage = new FlxGroup;
lyrStage2 = new FlxGroup;
lyrSprites = new FlxGroup;
lyrEye = new FlxGroup;
lyrEye2 = new FlxGroup;
lyrBlind = new FlxGroup;
lyrBlind2 = new FlxGroup;
lyrHidden = new FlxGroup;
}

//Adding the player and other objects


//all the objects
_exitDoor = new ExitDoor();
_player = new Blip(16, 160, null);
_eye = new Site(16, 160, null);
_eye2 = new Site2(16, 160, null);
_blind = new Blind(0, 0, null);
_blind2 = new Blind2(0, 0, null);
lyrBlind.add(_blind);
lyrBlind2.add(_blind2);
lyrEye.add(_eye);
lyrEye2.add(_eye2);
lyrSprites.add(_exitDoor);
lyrSprites.add(_player);
// lyrBlind.add(_blind);
// lyrSprites.add(_eye);
_hidden = new HiddenLevel(0,0,null);
lyrHidden.add(_hidden);
//lyrEye.add(_hidden);
//_hidden.visible = false;

darkness = new FlxSprite(0, 0);
darkness.createGraphic(FlxG.width, FlxG.height, 0xffffffff);
darkness.scrollFactor.x = darkness.scrollFactor.y = 0;
darkness.alpha = 0.888;
       
 

this.add(lyrStage2);


this.add(lyrEye);
//this.add(lyrHidden);
//hidden is behind blind
//this.add(lyrBlind);
//this.add(darkness);

//blind is behind everything
this.add(lyrStage);
this.add(lyrSprites);







//this.add(lyrEye2);
// lyrSprites.add(lyrEye);
//this.add(lyrBlind2); 



//Tile Map

{

//main tilemap
_tilemap = new FlxTilemap();
_tilemap.drawIndex = 0;
_tilemap.collideIndex = 2;
_tilemap.loadMap(new TxtMap, ImgTiles, 16);

  lyrStage.add(_tilemap);
  //invisible tilemap
 
  _tilemap2 = new FlxTilemap();
  _tilemap2.visible = false;
 
_tilemap2.drawIndex = 0;
_tilemap2.collideIndex = 2;
_tilemap2.loadMap(new TxtMap2,ImgTiles2,16);
  lyrStage2.add(_tilemap2);
// _tilemap2.visible = false;  
}


//Misc stuff

{
///////////////////////////////
// FlxState.bgColor = 0xffacbcd7;

//the tell the mouse to be shown with the icon here
//FlxG.mouse.hide(ImgCursor);

title_text = new FlxText(100, 20, 290, '"platformer movement with a tilemap and a background image"');
title_text.color = 0xffff88;
//Soundtrack
FlxG.play(clickSound, 1, true);


FlxState.bgColor = 0xffffffff;

//0x66161616
//white-0xffffffff
//black-0xff0000000
}

//add tilemap last

{

//previously known as ImgDark in other classes
//levels that do not have two tile maps in them will have
//all commented out code deleted.
{
var white:FlxSprite;
white = new FlxSprite(0, 0, ImgWhite);
white.blend = "hardlight";
//white.blend = "layer";
white.alpha = 1;
//_sight.blend = "invert";


//lyrStage2.add(_tilemap2);

}
//invisible tile mask
//add tilemap last

//Order of appearance for effect to work
//stage2 is hidden tilemap
//white is screen cover object
//stage is the visible tile map
//sprites is the character and all the moving bits








//player sprite, etc



//Fade in.
{
fed = new FlxSprite(0, 0, ImgFed);
fed.blend = "screen";
counter += FlxG.elapsed;
fed.alpha = 0.88;

this.add(fed);
}


}

//super
super.create();

}

//Attempting to go to the next stage
override public function update():void

{

//title_text.update();

//return to menu
if(FlxG.keys.ENTER)
{
FlxG.state = new BlipMenu();
}
if(FlxG.keys.UP && _player.overlaps(_exitDoor))
{
//FlxG.play(clickSound2);
FlxG.state = new BlipMenu();

}
if(FlxG.keys.UP && _player.overlaps(_exitDoor))
{
//FlxG.play(clickSound2);
FlxG.state = new BlipMenu();

}
if(FlxG.keys.FOUR)
{
//FlxG.play(clickSound2);
FlxG.state = new BlipLevelTest1();

}
if(FlxG.keys.C)
{
_hidden.flicker(1);

}
//for fading in
//thanks to hectate on the forums
fed.alpha -= 0.004;
if ( fed.alpha <= 0)
{
fed.kill();
}


//eye.visible = false;



_eye.y = _player.y-44;
_eye.x = _player.x-44;

_eye2.y = _player.y-44;
_eye2.x = _player.x-44;


super.update();
_tilemap.collide(_player);
//make sure to add collision on the "invisible" stage
_tilemap2.collide(_player);
//fake stages do not get collision >:D

//FlxU.overlap(coins,player,getCoin);
//overlaps go here


}

override public function render():void
{
darkness.fill(darkness_color);
super.render();
}
//Next stage
private function onFade():void
{

FlxG.state = new TutorialBlipping();

// FlxG.play(clickSound,1,true);
}

//Return to main menu
private function onFade2():void
{
FlxG.play(clickSound2, 1, false);

}
private function onFade3():void
{
FlxG.play(clickSound2, 1, false);

}


}

}

Player
Code: [Select]
package
{
import org.flixel.*;
public class Blip extends FlxSprite
{
[Embed(source = 'pics/Blip.png')] private var ImgPlayer:Class;
//[Embed(source = 'pics/blipSight.png')] private var ImgSite:Class;
[Embed(source = 'pics/glowLight.png')] private var glowLight:Class;

private var _player:Blip;
private var _vision:Site;
private var _move_speed:int = 800;
//private var _jump_power:int = 400;
public var _max_health:int = 10;
public var _hurt_counter:Number = 0;
private var _jump_max:int = 0;

public var glow:FlxSprite;
//adding both objects


public function Blip(X:Number,Y:Number, Stars:FlxGroup):void
{
super(X,Y);
loadGraphic(ImgPlayer, true, true, 16, 16);

//Max speeds
maxVelocity.x = 100;
maxVelocity.y = 160;
acceleration.y = 500;
//set the player health
health = 10;
//Gravity
//acceleration.y = 500;
//Friction
//drag.x = 300;
drag.x = maxVelocity.x * 4;
drag.y = maxVelocity.y * 4;
//drag.y =300;
//bounding box tweaks
width = 16;
height = 16;
offset.x = 0;
offset.y = 0;
//Animation setup
addAnimation("walking", [5,6, 7, 8,9,10,11,12,13], 12);
addAnimation("jump", [0]);
//addAnimation("attack", [4,5,6],10);
addAnimation("stopped", [0],8);
//addAnimation("hurt", [2,7],10);
//addAnimation("dead", [7, 7, 7], 5);
facing = RIGHT;

//this.y = FlxG.height - 48;

glow = new FlxSprite(0, 0, glowLight);
glow.scale = new FlxPoint(2, 2);
glow.alpha = 2;
glow.blend = "screen";


}
override public function update():void
{
/*
if (dead)
{
if (finished) exists = false;
else
super.update();
return;
}
*/
//health check
if (_hurt_counter > 0)
{
_hurt_counter -= FlxG.elapsed * 3;
}
//restarting the game on falling death
if(y >= FlxG.height-height+12)
{
FlxG.state = new TutorialBlipping;
//y = FlxG.height-height+12;
}

//move left and right
if (FlxG.keys.LEFT)
{
facing = LEFT;
velocity.x -= _move_speed * FlxG.elapsed;
}
else if (FlxG.keys.RIGHT)
{
facing = RIGHT;
velocity.x += _move_speed * FlxG.elapsed;
}
{
//jumping
if ((FlxG.keys.pressed("X") && onFloor && FlxG.elapsed ))
{
//velocity.y =  -_jump_power / 3;
//velocity.y -= 0.004;
velocity.y = -acceleration.y*0.41;

}

if ((FlxG.keys.pressed("X") && velocity.y < 0  && FlxG.elapsed))
{
//velocity.y = -_jump_power / 3;
//velocity.y -= 0.004;
velocity.y = -acceleration.y*0.41;
}

//the power of SITE




//getting ready for ducking :)
/*if ((FlxG.keys.pressed("DOWN") && velocity.y < 0  && FlxG.elapsed))
{
play("down");
}
*/
//Checking for specific tile collision
//or not, must check for spike graphic then

}

//animation assignments

if (_hurt_counter > 0)
            {
                play("hurt");
            }
else           
            {
                if (velocity.y != 0)
                {
                    play("jump");
                }
                else
                {
                    if (velocity.x == 0)
                    {
                        play("stopped");
                    }
                    else
                    {
                       play("walking");
                    }
                }
            }

super.update();


}

     
        override public function hurt(Damage:Number):void
        {
            _hurt_counter = 1;
            return super.hurt(Damage);
        }       


}
}

Would anybody mind pointing me in the right direction? I'd be satisfied with working shadows if anything.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

zyxstand

  • Member
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #1 on: Mon, Jul 26, 2010 »
I doubt many people want to go through so much code.
Do us a favor and give us a highly simplified version of what you want - no sounds, no collision detection - basically ONLY the lighting part.

I haven't checked your code, but you're probably gonna use flxsprite blending afaik. i was trying to find some simple help links for you but without much luck. anyway, show us your code again simplified and we can work with that easier!

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #2 on: Tue, Jul 27, 2010 »
Well, people normally want everything, but okay.

Playstate
Code: [Select]
//darkness
private var darkness:FlxSprite;
private var darkness_color:uint = 0xffff88;

override public function create():void
{
darkness = new FlxSprite(0, 0);
darkness.createGraphic(FlxG.width, FlxG.height, 0xffff88);
darkness.scrollFactor.x = darkness.scrollFactor.y = 0;
darkness.blend = "multiply";
darkness.alpha = 1;

//the layers in which it's added
this.add(lyrStage2);


this.add(lyrEye);
//this.add(lyrHidden);
//hidden is behind blind
//this.add(lyrBlind);

this.add(darkness);

//blind is behind everything
this.add(lyrStage);
this.add(lyrSprites);

//super
super.create();

}//i use these alot to group stuff together so my screen isn't //so cluttered


Player
Code: [Select]
[Embed(source = 'pics/glowLight.png')] private var glowLight:Class;

public function Blip(X:Number,Y:Number, Stars:FlxGroup):void

glow = new FlxSprite(0, 0, glowLight);
glow.scale = new FlxPoint(2, 2);
glow.alpha = 2;
glow.blend = "screen";

That's all that has to do with the lighting I'm trying to do. Although, looking through his code again I don't think I've added everything. I'll look at it a bit more and play with it a little. I'll also fire him off a pm to see if he wouldn't mind to explain to me some details and hopefully point out what I'm missing.

*I realized this earlier that I had nothing about the array. My tiles consist of 16x16 blocks. Which would mean that's the size of the game grid as well. I saw the flash dojo's EZ game with an array in it and only briefly looked at it. I was wondering a couple things though.

1: When I set up the array, does it have to be set up inside the playstate or can it be embed?
2: Regardless of embeding or not, since the array is made of numbers, can I gather a number from the array, say 3. And then have a function(s) that put certain objects at the positions of those numbers? Say for instance, for every number 3 that is in the array create "x" object?
« Last Edit: Tue, Jul 27, 2010 by xhunterko »
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #3 on: Wed, Jul 28, 2010 »
Howdy -

I added a snippet on Flashgamedojo about  dynamic lighting/shadows.

Can you take a look and tell me if it's helpful or if you have any issues with the technique I've described or the way I've described it?

I don't think I follow your question about arrays, sorry.  Maybe you could rephrase it or post some code?
« Last Edit: Wed, Jul 28, 2010 by racter »

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: "Shadows", arrays questions
« Reply #4 on: Wed, Jul 28, 2010 »
1. Yeah, you can embed it as a text file, what do you think flxtilemap is using?
and for 2
Code: [Select]
var tmpArray:Array = (embedded csv array as String).split("\n");
for (var tmpi:int = 0; tmpi < tmpArray.length; tmpi++)
{
string += tmpArray[tmpi] + ",";
}
if (tmpi == tmpArray.length)
{
array = string.split(",");
}
for (var i:int = 0; i < array.length; i ++ )
{
if (i % _map.widthInTiles == 0 && i > 0)
{
eY += 1;
}
if (array[i] == a number)//add sprite
{
sprite = new flxsprite ( (i - (_map.widthInTiles * eY)) * 16,eY * 16);
add(sprite);
}
}
That will take a string that happens to be a csv array, convert it into a 1 dimensional array, and loop through it placing sprites at the correct X & Y positions. Its basically the same code Im using to place sprites in my current project. If you are not using a csv array, but some other sort of array, you will have to modify the top bit where it converts the string into a 1 dimensional array. Also note, that this code assumes the array is the same size as your games map, as it is using the width of the games tilemap to determine the Y values.
*EDIT* Oh yeah, and eY should be var:int = 0, before the for loop starts. Its the current Y coordinate of the sprite being placed. (well, 1/16th of the current y coordinate.)
« Last Edit: Wed, Jul 28, 2010 by zez »

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #5 on: Wed, Jul 28, 2010 »
@racter: Following the link in your pm yields this: "There is currently no text in this page." Is there a delay process for new submissions? Or am I at the wrong page?

@Zez: Okay, I think I get what that is. But what does "i" stand for and well, could you explain the formulas better so I don't try to modify it and mess it up somehow? Also, for the "sprite =" part, I can just replace sprite with a pre-existing class object right? Like say, I have an as file called FakeExit that has it's own code and is embedded to the playstate. To add it I just replace FakeExit with sprite right? And what does the formula after that do? I know it's for placement, but how does it use that to place one of x object on every 3 position in the grid? Sorry, I'm sure that'll work, but I'm a little confused as to how. Oh, I think I see what the string split part means. I was like, wha?
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: "Shadows", arrays questions
« Reply #6 on: Wed, Jul 28, 2010 »
okay... so i is just an integer, what its doing is looping through every index within the array. (i starts at zero, wile i is less the the length of the array, add one to i.)
The bit that is if(i % map.widthinTiles == 0 && i > 0){eY += 1;} is adding 1 to your y value every time you reach a number that is perfectly divisible by the width in tiles, meaning whenever you hit the end of a row, it goes to the next columns value. You can then use these two values to get the X and Y coordinates. The y coordinate is just eY * whatever the size of the 'tile' you are using is, so 16 in this case. The X coordinate is a little bit trickier, as the value of i will be every single possible value within the array, and not just a pure X value, however, sense you know the y value (eY) you can just multiply that by the width in tiles of your map (like I did) and subtract it from i, to get the X 'tile' value. Then you just multiply your x 'tile' value by the width of a tile (16 in this case) to get the proper x coordinate in pixels.

what if(array[ i ] == a number) is doing, is just checking to see if the array value at the index i is equal to a number that theoretically represents your sprite, and if it is, creates it and places it based that equation in the paragraph above. So, the 'sprite' variable Im using there is getting passed (X coordinate, Y coordinate) just like any flxsprite should, and yes, it can be any other variable. You can infact use if(array[ i ] == 1) {goat = new goat( (i - (_map.widthInTiles * eY)) * 16,eY * 16); add(goat);} if (array[ i ] == 2) {cheese = new cheese( (i - (_map.widthInTiles * eY)) * 16,eY * 16); cheese.smell = "really smelly"; cheese.health = 23; add(cheese);} or pretty much whatever else you want using this method.

If you only have 3 positions in your grid, however, you might as well just do it manually instead of using a for loop, the way I have it set up right now, its designed to work with an array the same proportions as your worlds tilemap, and place sprites that way, so you can just edit a csv array in whatever map editor rather then having to manually plug away at sprites, or load in an xml file or some other such nonsense. In other words, this is a good way to do it if you have a large space you are filling with relatively small sprites (for example, I place my enemys and powerups this way, enemys averaging out to being around 16*32 and powerups being 16*16)

*EDIT* Good call zyxstand, I feel silly.
« Last Edit: Thu, Jul 29, 2010 by zez »

zyxstand

  • Member
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #7 on: Wed, Jul 28, 2010 »
careful with putting [ i ] (without spaces) as regular text zez, it turns the rest italicized instead of being displayed :P

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #8 on: Wed, Jul 28, 2010 »
Oh.

I think I see what's going on now.

So this:

(embedded csv array as String)

Would be something like first embedding the txt file, ie, a tilemap file, only it would be an array file, but embedded the same way with the mime types like this:

[Embed(source="maps/blipLevel2JumpingTut.txt",mimeType="application/octet-stream")] private var TxtMap:Class;
      
Then the earlier line would then be seen as this:

("TxtMap")//or whatever the sprite array is called

Correct?

Now, suppose I get my "shadows" working, what if I want to add one sprite array in front of the "shadows", and another array behind the shadows? Where would I put "add(sprite)"? Or do I have to have to do something like "this.add(array)"?
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #9 on: Wed, Jul 28, 2010 »
@xhunterko - I think the forum's auto-linking got confused by the parentheses in that url. Try this: http://bit.ly/bfsfc3

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: "Shadows", arrays questions
« Reply #10 on: Thu, Jul 29, 2010 »
noooooooooooo dont add the array.
You would do it the same way you normally would make something render infront of or behind something else, using a group. So if you want the shadows infront of everything, after you have added everything else to the state, you would add(shadowgroup); then when you add the shadow, it would be shadowgroup.add(shadow); instead of add(shadow);
That, or just run the process after everything else is added....

Also, if you plan to add a 16x16 sprite to every possible area on a map, first off, you actually can bypass all the array stuff and just us this
Code: [Select]
for (var i:int = 0; i < _map.totalTiles; i ++ )
{
if (i % _map.widthInTiles == 0 && i > 0)
{
eY += 1;
}
sprite = new flxsprite ( (i - (_map.widthInTiles * eY)) * 16,eY * 16);
add(sprite);
and second off, you are probably going to just want to use a single sprite with the proportions flxg.width, flxg.height; along with some drawing stuff to get your affect.

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #11 on: Thu, Jul 29, 2010 »
@Racter: Yes, that works now. I can't wait to test it out!

@Zez: Hmm, okay. I'll probably try the first method first. Since all I'm going for is object placement. Shouldn't be too much of a problem. Then their own behaviors would take care of gravity, movement, yadda yadda.

Thanks alot though guys. I appreciate it and hopefully I'll have some results to show later this weekend. :)
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #12 on: Thu, Jul 29, 2010 »
@racter: This code snippet here:

Code: [Select]
override public function render():void {
      var screenXY = getScreenXY();
 
      darkness.draw(this,
                    screenXY - this.width / 2,
                    screenXY - this.height / 2);
    }

I have this here, which is basically the same thing:

Code: [Select]
override public function render():void
{
var screenXY = getScreenXY();

darkness.draw(this, screenXY - this.width/2, screenXY - this.height/2);

}

However, I get the following error:

Code: [Select]
Warning: variable 'screenXY' has no type declaration.
I tried adding a lite:screenXY and etc but I still got errors. Although I'm puzzle because that should work. It's just a stand alone variable in it's own function right? That method works for other functions, so why not this one?
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #13 on: Thu, Jul 29, 2010 »
Ah, thanks for that.  It's just a warning so the code should still compile, but I'll add an explicit type declaration in the sample code.  it should be FlxPoint, so:

Code: [Select]
var screenXY:FlxPoint = getScreenXY();

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #14 on: Thu, Jul 29, 2010 »
Did that, now it's giving me this:

Code: [Select]
Error: Implicit coercion of a value of type org.flixel:FlxPoint to an unrelated type Number.
With the errors showing up at the screenXY part in this line:

Code: [Select]
darkness.draw(this, screenXY - this.width/2, screenXY - this.height/2);

Did you get the same error? I don't know what I'm doing wrong here, hmm.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #15 on: Thu, Jul 29, 2010 »
Sorry, that's just a typo in my code ;)  I was copying the code out of a full game, so I didn't test it separately.  I've fixed the code on the wiki, that line *should* be:

Code: [Select]
darkness.draw(this, screenXY.x - this.width / 2, screenXY.y - this.height / 2);

Thanks for helping debug this tutorial!

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #16 on: Thu, Jul 29, 2010 »
Biig problem!

I don't think it's quite debugged for me yet. When I go to the state that has the shadows in it, the previous state doesn't fully unload!

I can tell this because at the title screen, I have a shortcut key set up to go to this level. When I hit the key, the music changes and all, but the menu is still shown. I can also test this by playing through it regularly.

In the particular stage, there's a pit in the middle with a wall in the center. The music restarts everytime you die because I just have it when the player leaves the screen area, ie falls off, the state just restarts itself. Here's a swf link to see what I mean:

http://www.swfcabin.com/open/1280464528

Hit x to go for a regular playthough. Even if you do "die" in the 2nd level, you still get taken to the third stage. At the menu though, hit 3 to be taken directly to it.

Code for the playstate has been unchanged. Except I added the darkness from the tutorial and I also put this code:

Code: [Select]
var light:Light = new Light(FlxG.width/2, FlxG.height/2, darkness);

Above the super.create(). Since I wasn't sure where it was supposed to go. I'm guessing below it now?

quick edit: Nope.
quick edit2: taking out super.render in my playstate achieved unloaded levels in exchange for a white screen. I don't think the function is being used anywhere so it's probably safe to delete it. Slight progress I guess.
quick edit 3: sorry for these, still experimenting. But taking out the whole function yields a small unloading from the title screen. But from stage 2 still doesn't unload. So, it's not the problem but at least it can be safely removed.
« Last Edit: Thu, Jul 29, 2010 by xhunterko »
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #17 on: Thu, Jul 29, 2010 »
In the particular stage, there's a pit in the middle with a wall in the center. The music restarts everytime you die because I just have it when the player leaves the screen area, ie falls off, the state just restarts itself. Here's a swf link to see what I mean:

http://www.swfcabin.com/open/1280464528

Hit x to go for a regular playthough. Even if you do "die" in the 2nd level, you still get taken to the third stage. At the menu though, hit 3 to be taken directly to it.

When I press '3' or finish level 2, the game just freezes.

Code for the playstate has been unchanged. Except I added the darkness from the tutorial and I also put this code:

Code: [Select]
var light:Light = new Light(FlxG.width/2, FlxG.height/2, darkness);

Above the super.create(). Since I wasn't sure where it was supposed to go. I'm guessing below it now?

You don't actually need to call super.create() since FlxState.create() doesn't do anything.  You can just put the line that initializes the light at the end of your create() method, or really at any point after you've initialized the 'darkness' property.

Would it help if I made a complete & working example and posted the code for that project and a SWF?  It's not a very complicated effect really, I just want the tutorial to be helpful and legible.
« Last Edit: Thu, Jul 29, 2010 by racter »

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #18 on: Thu, Jul 29, 2010 »
I suppose it wouldn't hurt. But as far as the overall freezing, I got no clue where that came from. Still, it is a good tutorial.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
Re: "Shadows", arrays questions
« Reply #19 on: Fri, Jul 30, 2010 »
Looks like you have a null object in your render somewhere. Couple suggestions. Instead of screenXY.x and screenXY.y try getScreenXY().x and getScreenXY().y. If that solves it the problem is that you are never creating your flxpoint. You could stick screenXY = new FlxPoint(getScreenXY()); somewhere in create, and make screenXY a private var:flxpoint, then in the render stick in screenXY = getScreenXY(); to get around that as well.
If that is not the problem, it might be that you want darkness.draw(screen , screenXY.x - this.width / 2, screenXY.y - this.height / 2);
My only other thought is that you may have never created the darkness sprite, so in create darkness = new flxsprite(); darkness.creatGraphic(flxG.width,flxG.height, 0x000000); or whatever... Im not really sure if thats how the darkness object should be set up (never done this particular effect,) but you get the idea.