Skip to main content
aymana52258163
Participant
March 13, 2015
Answered

problem in creating a maza game by drowing line

  • March 13, 2015
  • 1 reply
  • 411 views

hi

i've created a maze game

the idea is to solve the maze by drowing a line

and its works fine as long as i didn't use any thing as a background.

the code

stop();

  import flash.display.Sprite;

  import flash.events.MouseEvent;

  var drawing:Boolean;

  var isStart = false;

  graphics.lineStyle(3,0x000000);

  drawing = false;//to start with

  stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);

  stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);

  stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);

  function startDrawing(event:MouseEvent):void{

  graphics.moveTo( mouseX, mouseY);

  drawing = true;

  }

  function draw(event:MouseEvent){

  if(drawing){

  graphics.lineTo(mouseX,mouseY);

  }

  }

  function stopDrawing(event:MouseEvent){

  drawing = false;

  }

stage.addEventListener(MouseEvent.MOUSE_MOVE, detectHits);

function detectHits(event:MouseEvent) {

if (wall_mc.hitTestPoint(mouseX,mouseY,true)) {

  if (isStart == true) {

  graphics.clear();

gotoAndPlay(3);

  isStart = false ;

stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);

  }

}

else if (hit_mc.hitTestPoint(mouseX,mouseY,true)) {

  if (isStart == true) {

  graphics.clear();

  gotoAndPlay(2);

  isStart = false ;

stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);

  }

}

}

mc_start.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void

{

isStart = true ;

}

i need to set a background to this game

but when i do the lines never drew

This topic has been closed for replies.
Correct answer dmennenoh

At the top of your code you have this:

graphics.lineStyle(3,0x000000);


Right before that do:


var drawingSprite:Sprite = new Sprite();

addChild(drawingSprite);


and then change your references from just graphics to drawingSprite.graphics:


graphics.lineStyle(3,0x000000);


should now be:


drawingSprite.graphics.lineStyle(3,0x000000);


1 reply

Inspiring
March 13, 2015

I think you're drawing behind your background. Add a new sprite and then draw into that instead.

aymana52258163
Participant
March 13, 2015

yes thats right but how ! and where 

dmennenohCorrect answer
Inspiring
March 13, 2015

At the top of your code you have this:

graphics.lineStyle(3,0x000000);


Right before that do:


var drawingSprite:Sprite = new Sprite();

addChild(drawingSprite);


and then change your references from just graphics to drawingSprite.graphics:


graphics.lineStyle(3,0x000000);


should now be:


drawingSprite.graphics.lineStyle(3,0x000000);