Or that's what I think, at least.
I just began with AS3 and I'm trying to do a little game where one ball moves on its own and the other one is handled by the player. So far, so good. That works.
What isn't working is hitTestObject(); it just returns true when it's like 2 cm from the other object. Here's a picture so you can see: http://dl.dropbox.com/u/37057843/coll2.jpg
I've read that hitTestObject just creats a rectangle around the objects and then tests for collisions on those rectangles, is it because of that?
If you need any piece of code I'll deliver. I know there are some other opensource libraries/engines like Box2D to solve this in a better way, but I don't want to jump to engines directly.
Thanks for reading!
Yes, hitTestObject will use the clips bounding box.
Check out this link, it has a lot of great information as well as a class that will do what you're looking for
http://sierakowski.eu/list-of-tips/39-collision-detection-methods-hittest-and-hittestobject-alternatives.html
Direct link to the package
http://code.google.com/p/collisiondetectionkit/
Related
I'm programming a game using ActionScript 3.0 and included Box2D classes for its physics. It's a maze/labyrinth game having a lot of walls and a ball inside.
In my main fla when I call the maze.create(), the maze is created (visually and physically) and it will dispatch an event so I know when it's done working and then I call my frameHandler which calls another function from my maze class every frame and the big delay accrues exactly at world.step() in it. BUT THE THING IS that it lags only the first two times this function runs!!!
The reason I notice this lag, is that I've got another object starting to move according to mouse position in the same frame handler.
The reason I'm sure the world.step() is causing it, is that everything works fine when I dont call it.
I've seen many codes using Box2d, some had more objects than i have and I know that I've created my b2World and all the objects correctly, similar to all the Box2d tutorials and stuff BUT THEY DONT LAG AT ALL. Its just mine lagging and all!!
Do you have any Idea or similar experience?
Do you have any suggestion in general how to deal with heavy functions?
PLEEEEASE +.-
A maze will have a lot of fixtures in close proximity making a very dense dynamic tree (the method Box2D uses to optimize collision checks). There is unlikely to be any way around this. Perhaps you could just call Step a few times after adding the static walls, but before you add the dynamic ball bodies, and consider it part of the loading process. At least the lagging movements will not be visible to the player.
I am learning to make games in Flash. I know I should probably use HTML5 or other platforms but let it be like this. I will learn those stuff later..
My question is like this, I want to select multiple characters in game. For example, I have 5 tanks. I want to drag-select them and move them to a point. How can I do that? Any mouseEvent or function for that? Moving them to a point is a different criteria I guess, but selecting a group of tanks. That's what I want to learn.
I am going to use Flixel game engine for this.
PSST! ~ If you guys don't want to help me, step by step by giving me exact code. I am fine! Just guide me in the right path and I will learn it myself.
First of all, do you know how to select one tank and move it where player clicked?
I'm not sure Is it an easy task for you. I'll give you some ideas about selection and how to detect it.
Bounds and Rectangles. Every tank has bounds represented as Rectangle, and by dragging your selection over tanks, you are forming also Rectangle. So you could check intersection of these rectangles
If you don't want to work with bounds, but with ready to use display object methods. By dragging Rectangle selection, you could form transparent shape, and check if it intersects with tanks This approach is slower than first.
I am making a tower defense game for a class of mine. I decided to use starling with Flash and I am having a bit of trouble. Is there any was for me to specify that the towers can only be dropped into place if they are with in the bounds of a specific image/ in a 100px range of a specified center point? I would want to be able to store the points to be able to reference as I will have about 10-20 spots to place the towers. I feel like I might just be over thinking this.
Any help or guidance would be great.
Maybe you can try the hitTest method and add some dummies for locate the placing. If your hitTest method returns a dummy object you know that you are on a good place.
see Starling DisplayObject:hitTest();
I am making a maze game and i have the edge of the maze as a movieclip. I'm trying to test if the player hit tests the maze to make him stop using this code.
If(player.hitTestObject(Maze))
{
function()
}
But wether or not It's actually touching the maze (it's in the empty space on the inside) it always registers as touching. Is there any way to fix this?
You won't have to use any physics api. They are too heavy and complex and your task is simple. Try replacing your hitTest method for hitTestPoint
if(Maze.hitTestPoint(player.x,player.y))
{
function()
}
Cheers!
This is what you're looking for:
http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/
The reason why hitTest always says true, is that it only checks to see if the bounding boxes for the two objects touch each other. More nfo on what that means can probably be found in the link above. What is in the link above, is an explanation of how to do pixel-perfect hit tests in flash. :) Also if you're doing a game using collision like this and/or any kind of physics, you may be interest in this tutorial:
http://gotoandlearn.com/play.php?id=135
It's a video about a world construction kit for Box2D, probably the most popular physics library for flash.
I'm trying to create a multi-level dungeon adventure in Flash CS4. The layout is an instance created of a symbol called Level, within the symbol are multiple wall subsymbols (wall), instances of Wall. There is a collision routine to stop the player walking through the walls, called from Wall.As.
Level is drawn about the centre point (0,0).
When I create an instance on the stage of Level (level), the collision tester is using the xy coordinates for the walls drawn about 0,0, not the "real" xy where it's appearing on the stage.
So what I need to know, is how to "update" the xy for each wall subsymbol with the live stage information, overriding the XYs drawn in the parent. It has to be updated unfortunately (I can't keep it static), as the levels are big so have to scroll.
Thanks for your advice.
With all due respect forget your approach, you're reinventing the wheel for nothing and probably to end up getting worse performance. What you need is pixel-perfect collision detection and probably including basic physics so already we're talking a huge amount of work. If you want to build levels in a design way for a game, use this, it'll blow your mind how awesome/easy/cool this is:
http://www.gotoandlearn.com/play.php?id=135
Its always a guess when trying to answer questions like this, as there are a lot of unknowns. That being said, in programming, there are always more than a few ways to solve a problem. Examine your collision detection routine - if you worked with hitTestPoint, and the point that was being tested (mouseX,Y or your main actor) with localToGlobal, you likely wouldn't need to test for the x,y variables of your collision objects. Read up on those two subjects and this question might be rendered moot.
At any rate, you could update relative coordinates in your Wall.as instance by leveraging globlaToLocal:
public function get curLoc():Point
{
return globalToLocal(new Point(this.x, this.y));
}
and retrieve them from your parent class as a point you can then test against:
trace(_wall.curLoc);
Hope that helps
I suppose you could accomplish what you're trying to do by manipulating the transform property of the wall symbols, but honestly I would concur with Ascension Systems and just abandon your collision testing routine for something different.
You may not need to go all out with a physics engine for your game, in which case just use hitTestObject to do the collision detection.