• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bounding Box Problem

New Here ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

I'm making a game where there falling random dots all connected with the next one, creating a long zigzag line. I've try to do a hitTestObject  but the bounding box of "fallingThingsLeft" makes the hitTest with Touch1 inaccurate. What can I do to make this to work???adobe.png

TOPICS
ActionScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

And here is my code:

import flash.display.Graphics;

import flash.display.MovieClip;

import flash.events.Event;

import flash.events.TimerEvent;

import flash.utils.Timer;

var objectSpawner: Timer;

var fallers: Array;

function initGame(): void {

          fallers = [];

          objectSpawner = new Timer(1000);

          objectSpawner.addEventListener(TimerEvent.TIMER, createEnemy);

          objectSpawner.start();

          addEventListener(Event.ENTER_FRAME, dropEnemies);

}

function createEnemy(e: TimerEvent): void {

          var enemy: Faller = new Faller();

          enemy.y = -stage.stageHeight;

          enemy.x = Math.random() * 380;

          MovieClip(enemy).cacheAsBitmap = true;

          addChild(enemy);

          fallers.push(enemy);

          drawConnectors();

}

function dropEnemies(e: Event): void {

          trace(fallers.length);

          for each(var mc: Faller in fallers) {

                    mc.y += 10;

                    if (mc.y > stage.stageHeight * 2) fallers.splice(fallers.indexOf(removeChild(mc)), 1);

          }

          drawConnectors();

}

function drawConnectors(): void {

          if (fallers.length == 0) return;

          var g: Graphics = this.graphics;

          g.clear();

          g.lineStyle(10,0xFFFFFF);

          var mc: Faller = fallers[0];

          g.moveTo(mc.x, mc.y);

          for each(mc in fallers) g.lineTo(mc.x, mc.y);

}

init()

function init():void

{

          var fallingThingsLeft:FallingThings = new FallingThings(stage.stageWidth / 2, stage.stageHeight);

          var fallingThingsRight:FallingThings = new FallingThings(stage.stageWidth / 2, stage.stageHeight);

          addChild(fallingThingsLeft);

          addChild(fallingThingsRight);

          fallingThingsRight.x = stage.stageWidth / 2;

var score = 0;

score_txt.text = score;

import flash.events.Event;

this.addEventListener( Event.ENTER_FRAME, handleCollision)

function handleCollision( e:Event ):void

{

if(fallingThingsLeft.hitTestObject(Touch1))

   {

   trace("HIT")

   updateScore();

   }

   else

   {

   trace("MISS")

   }

}

}

function updateScore ():void

{

score_txt.text += 1;

}

}


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2014 Apr 24, 2014

Copy link to clipboard

Copied

sorry for losing sight of your other posting...  What you should do is look into using bitmapdata hitTest.  Search Google using terms like "bitmapdata hittest" and you will find a number of results that can help explain it.  Here is one of the results...

http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 25, 2014 Apr 25, 2014

Copy link to clipboard

Copied

Instead of doing that, why not just read the size of the box (once), then chart a course to random x points within the box, with the y always going up?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 25, 2014 Apr 25, 2014

Copy link to clipboard

Copied

Sorry but im not sure to understand..??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 25, 2014 Apr 25, 2014

Copy link to clipboard

Copied

Rather than send it off in a direction and change that direction once it hits the box, why not just set the path so it is always within the box?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

What is the expected behavior?

1. Do you want hit test to performed on entire panel where all objects inside FallingThings instance are hit tested (dots and lines) or you need a hit test for dots only?

2. What do you need to do once hit is detected?

Also, where is the code that implements hittest? Did I miss it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

Yes all dots and lines (on both side) and when a button is hit we need to press it and if not it's game over.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

I see at least one potential conflict in the vision. Lines/connectors can hit several adjacent buttons at the same time and remain in the state of been hitting buttons for some time. While line is moving down over button(s) - hit test will be true as long as pane is over/touching the button.

On the other hand, user should have a reasonable amount of time to press the button. This is significant because of the need for a certain interval between the moment hit test becomes true and button click produces a win - otherwise game may become user unfriendly to the extend of being useless/unwinnable.

Basically, I am yet to envision all valid use cases. I sense that depending on entire complex of usability aspects your approach may deem unfeasible.

As a side note, Ned's suggestion to look into bitmapdata hittest appears like the most robust one given everything else is in place.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

In fact , my (mobile) game consist at when both lines touch a given space at the bottom of the screen, the player need, with his thumbs, to follow both lines going in zigzag and increasing in speed. The player makes 1 point for each hit ball and the game ends when the player is not able to follow a line.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

Does hit test problem relate to zigzags touching objects at the bottom? In other words, do you experience a difficulty to detect when zigzags hit the bottom?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2014 Apr 26, 2014

Copy link to clipboard

Copied

yes exactly

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2014 Apr 28, 2014

Copy link to clipboard

Copied

Well if you didn't find any other solution, I will try the bitmapdata hittest and the example of Mike Chambers. But I am a bit confused with the names that I need to change with. Like blueclip with Touch1 and redclip with...?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2014 Apr 30, 2014

Copy link to clipboard

Copied

LATEST

Faller, fallers, fallingThingsLeft, fallingThingRight, FallingThings, enemy, mc ...????

There is nothing that works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines