Type object selection using camera pick
Blitz3D Forums/Blitz3D Programming/Type object selection using camera pick
| ||
Its been a while since I used Types but have recently got back into the swing of things. I am presently working on a little project where ships circle an island. When I point the camera to a ship from the island, I would like to select the ship, however I am using camera pick to pick out the ship (sprite) but it always reports the last ship in the type list to be created and not the actual ship looked at (Ships ID for that type entry) I have the ships circling using the function below Function updateships() For s.ship = Each ship Local shipx#, shipz# Local shstart =200 ;Update position around radius using the sin/cos functions shipx# = S\SCX# - ( Cos#(S\SA#) * S\SDS# ) shipz# = S\SCZ# + ( Sin#(S\SA#) * S\SDS# ) ;draw the ship PositionEntity S\SIMAGE,shipx#,S\SY#,shipz# RotateEntity S\SIMAGE,0,(90-S\SA#),0 ;update shipangle# and maintain speed at different distances S\SA#=S\SA#+(S\SP#/S\SDS#) SA=S\SA#; SNAME1=S\SNAME SX1#=shipx# SZ1#=shipz# SSP1#=S\SP# SDS=S\SDS# SDE=S\SDE# SIMAGE=S\SIMAGE SID=S\SID% Next End Function Function selectship() And a camera pick function picked = CameraPick(camera,378,278) If Picked > 0 sh$ = "Ship ID picked" sh$ = sh$ + SID% Else sh$ = "Nothing" EndIf End Function Is there a way of reporting back the actual sprite being looked at. I have 3 ship type's defind but cant remember how to report back on individual S\SID% when the camera picks it. Appreciated, Thanks, |
| ||
You might name your sprites with the corresponding name or id: NameEntity sprite,shipName$ Later on you can retrieve the name of the picked entity like so: ShipName$=EntityName(PickedEntity()) After this, search in your ship type list for the proper name. |
| ||
Also, using the Object() and Handle() commands, you can obtain an integer pointer to the Type, which can be used as the name of the entity. This way, you don't need to search through the list, but you can directly get the Type object that the entity belongs to. Out of my head, that would be along the lines of this: sh.ship = New ship sh\sprite = CreateSprite() NameEntity sh\sprite, Handle(sh) .. ShipID=EntityName(PickedEntity()) If ShipID <> 0 then sh.ship = Object.Ship(ShipID) ..use sh.. End If |
| ||
Warner's way is the quickest. As soon as you pick the entity, you can get the type object, just from the entity name. |
| ||
Thanks for the response. Warner, your method does the trick. Did not see any details on handle and object in the docs relating to types.... I will be using this select process for detecting ships when pointing a long gun at them from an Island via camerapick to sprite....Nice code thanks... |
| ||
They are undocumented commands, as they are not offically supported i believe. |