I’m trying to make use of JBanes’ Gage CollisionMap.
I have added it into my code but when I go to check for a collision,
my values are wrong. The reason is because the getX of the ImageSprite class
don’t seem to be correct. i.e. if the sprite is in the top left corner of the map,
getX/getY return 0 , even If the map is scrolled to the middle.
I guess in short i need some help setting up the sprite movement. any Ideas? ???
Another note on this. How do I get the “Walk until you hit the edge then scroll the map”" effect. I think Zelda did stuff this way.
Actually, that’s a coding mistake on your part. GAGE allows you to use any coordinate system you want. However, if you want your sprites to be aligned with the map, you need to use Map coordinates, not screen coordinates. Thus, if the map is scrolled to 300px in the X direction, your sprite needs to be set to 300px to be in the upper left hand corner. Remember tho, that the sprite won’t show up on the screen in the right place unless you pass map coordinates for it’s location! Like this:
sprite.render(g, -map.getX(), -map.getY());
If you look at the shooter example, you’ll note that all sprites are rendered this way. As for stopping at the edge of the map, that is simple logic. Something like this:
if(sprite.getX() < 0) sprite.setX(0);
if(sprite.getX()+sprite.getWidth() > map.getPixelsX()) sprite.setX(map.getPixelsX()-sprite.getWidth());
Thanks;
But how do I get the “map” coordinates of the sprite so I can
test for collision against the CollisionMap?
You just set the coordinates as such. In other words, you probably have X set between 0-640 because that’s the extent of the screen, right? Using map coordinates, X would be 0-map.getPixelsX(). Once you use the range of the map, just call:
sprite.render(g, -map.getX(), -map.getY());
instead of:
sprite.render(g, 0, 0);
and your sprites should render whereever on the map they’re located.
Thanks Again;I understand now. ;D
Awesome, my demo is working great now.
Thanks again. Only one problem. How do I take the dorection of the sprite into
account for collisionMap. If is use the getX/getY method, I end up on block onto a colliding block, if coming from the left, if coming from the right everything is
OK.
[quote]How do I take the dorection of the sprite into
account for collisionMap. If is use the getX/getY method, I end up on block onto a colliding block, if coming from the left, if coming from the right everything is
[/quote]
I assume you’re only checking the X,Y of the sprite? As you might of guessed, this isn’t going to work. Calling getCollision() and isCollision() only tells you if a collision occurred at exactly that pixel. To tell if the actual sprite intersects, you need to test either every pixel in the sprite or - if you know the direction - the leading edge of the sprite. (i.e. The right edge would be (sprite.getX()+sprite.getWidth(), sprite.getY()) - (sprite.getX()+sprite.getWidth(), sprite.getY()+sprite.getHeight()) )
I was going to upload a new version of GAGE with the final CollisionMap class in it (including sprite checking), but SBC happily gave my phone line to someone else. They’re supposed to fix it today, but I don’t have high hopes. The last time they did this (seems to be the norm for them) the guy came out and said the line was fine and left without fixing it. We had to make them get a guy out again, and then they wanted to charge us for the visit! I swear, only utility companies can get away with service like this. >:(
thanks;
I kinda figured that. I’ll be anxiously awaiting your new release.
Krypto.
The new release is out and it’s rockin I’ve already integrated it into my game, good stuff.
I really like the new StatefulSprite, great …