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

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #20 on: Fri, Jul 30, 2010 »
I tried the getScreenXY() and that didn't do anything. I'll try the others later. However, commenting out the entire line does not cause a crash. So it's just that line hopefully. I'll try the rest later.
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 #21 on: Sat, Jul 31, 2010 »
I think a problem with that other method zez is that the error occurs in the Light.as file. Not the playstate.
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 #22 on: Sat, Jul 31, 2010 »
Oh, my bad, the error it threw from my browser based copy was in the playstate. Post the code to the light.as file?

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #23 on: Sat, Jul 31, 2010 »
Basically the same as this here:

http://flashgamedojo.com/wiki/index.php?title=Dynamic_Lighting_%28Flixel%29

Code: [Select]
package
{
import org.flixel.*;


public class Light extends FlxSprite
{

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

private var darkness:FlxSprite;



public function Light(X:Number,Y:Number,darkness:FlxSprite):void
{
super(x, y, Lite);

this.darkness = darkness;
this.blend = "screen";


}
override public function render():void
{
// var screenXY:FlxPoint = getScreenXY();
var screenXY:FlxPoint = getScreenXY();

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

}
   
       }
}

Since it crashes for me, I looked around and found another tutorial on Tigsource using Box2d. And even though I'm importing everything the tutorial that the FlashDojo provides I'm still getting this error:

Code: [Select]
Error: Type was not found or was not a compile-time constant: b2Vec2.
The tigsource tutorial I'm following is here:

http://forums.tigsource.com/index.php?topic=8803.0

I'll be in chat later to see if other people got Box2d accepted somehow.
Thanks in advance.

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 #24 on: Sat, Jul 31, 2010 »
The problem with the simple one you have posted here, is that
Code: [Select]
public function Light(X:Number,Y:Number,darkness:FlxSprite):void
{
super(x, y, Lite);

this.darkness = darkness;
this.blend = "screen";


}
should be
Code: [Select]
public function Light(X:Number,Y:Number,[u]D[/u]arkness:FlxSprite):void
{
super(x, y, Lite);

this.darkness = [/u]D[/u]arkness;
this.blend = "screen";


}
or something along those lines. What you have now is telling light that darkness = itself, so if you want to pass it another instance of darkness, you need to have the name of the variable you are passing be different then the variable you are passing it too.

As for the box2d bit, it looks like you just didnt import correctly, or failed to pre-load box2d.

racter

  • Active Member
  • ***
  • Posts: 100
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #25 on: Sat, Jul 31, 2010 »
The 'this.darkness' part of that line makes it unambiguous actually, so that's not really causing an issue.  The compiler is smart enough to know that 'this.darkness' means the property 'darkness' and 'darkness' means the local variable darkness (the argument to that method).

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: "Shadows", arrays questions
« Reply #26 on: Sun, Aug 1, 2010 »
I found the source of the Box2d error I believe. When I started a clean project to test the entire tutorial on FlashDojo I hit run with nothing but the simple importing and setting up the world. Lo and behold, it threw errors, but not in MY code. The errors were coming from Box2d API itself. And I have no idea how to fix those.

However, with a clean level, I used the opportunity to try racter's tutorial again. I'm not throwing any errors at all this time. The only problem is the light won't show up. I've added a couple alpha values I think to test positioning, but that's it.

Playstate
Code: [Select]
package 
{
import org.flixel.*;



public class BlipBox2d extends FlxState
{
[Embed(source="noise/OneAtATime.mp3")] private var clickSound:Class;
[Embed(source="pics/blipTileset.png")] private var ImgTiles:Class;
[Embed(source="maps/BlipTestingLevel1.txt",mimeType="application/octet-stream")] private var TxtMap:Class;
//showing the mouse is simple, embed the image for your icon
[Embed(source="pics/cursor.png")] private var ImgCursor:Class;

//Adding a background image
[Embed(source = "pics/blipMockupA.png")] private var ImgBG:Class;

private var darkness:FlxSprite;
private var background:FlxSprite;



override public function create():void
{
background = new FlxSprite(0, 0, ImgBG);

darkness = new FlxSprite(0, 0);
darkness.createGraphic(FlxG.width, FlxG.height, 0xff000000);
darkness.scrollFactor.x = darkness.scrollFactor.y = 0;
darkness.blend = "multiply";
//background.alpha = 0.855;
darkness.alpha = 0.755;

add(background);
add(darkness);
//super
//super.create();

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


add(light);
//super.create();
}

override public function render():void


{
darkness.fill(0xff000000);
super.render();

//super.update();

}


}

}

Light
Code: [Select]
package
{
import org.flixel.*;


public class Light extends FlxSprite
{

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

private var darkness:FlxSprite;



public function Light(x:Number,y:Number, darkness:FlxSprite):void
{
super(x,y,Lite);

this.darkness = darkness;
this.blend = "screen"

}
override public function render():void
{
var screenXY:FlxPoint = getScreenXY();

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

And no errors is a good thing right?
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