Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Sprite Transparency and collision

Author
Message
damothegreat
User Banned
Posted: 27th Oct 2016 18:08
Hello

Here is the idea, would like to progress further with a racy style demo

But before I continue, would like to ask if my method is do-able.

I have attached a few files.

- Background.png - (background pick - 1st layer)
- level1trans.png - (Transparency image, which shows just the outsides of the race track)
- kevel1track.png - (Image to overlap to show the rest of the detail)

Loading in sequence

background=createsprite(loadimage("background.png"))
level1trans=createsprite(loadimage("level1trans.png"))
level1track=createsprite(loadimage("level1track.png"))

LoadImage(1,"NewCars1.png")

Splendid so far... and looks wicked...

But here is the snag of what I'm trying to want to achieve.

Moving the car around on the screen - know the code the rotate/speed up/slow down... cool..

but what I would like is theorectically

Add collision detection for the car with the level1trans.png sprite (which has transparency), so if the car hits any of the level1trans image then make the car bounce/stop to a halt

It doesn't, cause AppGameKit is colliding with *all* of the level1trans image, so its not ignoring transparency where I would like it to.

Can the above be achievable before I have more time on it.

Thanks
Damo



Using Tier 1 AppGameKit V2
Started coding with AMOS

Attachments

Login to view attachments
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 27th Oct 2016 18:38
For "pixel perfect" collison, you may need to sample the alpha channel manually for any pixels occupied by the car


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Oct 2016 09:41
I would create the track from multiple sprites, and add collision to each sprite. You can create irregularly shaped collision shapes (convex only) around each sprite, or combine multiple sprites and multiple collision shapes to make more complex obstacles.
By doing it this way, you make any system for making multiple tracks much easier, being able to move obstacles and use them in multiple tracks. You can also add physics (manually or automatically) that make the obstacles move when hit.

An alpha image with obstacles in the centre of it is essentially a concave shape. Collision systems only deal with convex shapes, where it can be divided into triangles with simple and efficient algorithms.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
User Banned
Posted: 28th Oct 2016 10:58
Thanks.

I shall prepare different style track shapes as smaller individual sprite images and using a map style array to implement the whole track on the locations of each track piece on the screen.

I.E
0 - Empty
1 = Upper Left corners
2 - Upper Right corners
3 - Lower Left corners
4 = Lower Right corner
5 - Horizontal Straight
6 - Vertical Straight.
7. Diagonals
etc
etc
etc
10. Starting Grid
11. Checkpoint 1
12. Checkpoint 2
13. Checkpoint 3
14. Checkpoint 4
15. Checkpoint 5

and map data could be

leveldata[level]=
[ 1, 5, 5, 11, 5, 5, 5, 2 ]
[ 6, 0, 0, 0, 0, 0, 0, 6 ]
[ 6, 0, 0, 0, 0 , 0 , 0 , 6 ]
[ 10, 0, 0, 0, 0 , 0 , 0 , 12 ]
[ 6, 0, 0, 0, 0 , 0 , 0 , 6 ]
[ 6, 0, 0, 0, 0 , 0 , 0 , 6 ]
[ 1, 5, 5, 13, 5, 5, 5, 2 ]

- Cars start on the starting grid = 10
- Cars must pass through once (in sequence) each of the checkpoints - 11, 12, 13 , 14, 15 (max 5 checkpoints on any track
- If cars pass the 0=Empty sprite then they bounce off to keep in the track

Hope this is a good method

Will look into it soon

Thanks
Damian



Using Tier 1 AppGameKit V2
Started coding with AMOS

Login to post a reply

Server time is: 2024-11-24 16:02:08
Your offset time is: 2024-11-24 16:02:08