Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who is Online
18 user(s) are online (15 user(s) are browsing Forum)

Members: 0
Guests: 18

more...


Browsing this Thread:   1 Anonymous Users






Re: How detect transparent part of sprite
#6
Home away from home
Home away from home


See User information
Beware that next release of PortablE renames "UsageCount" to "VisibleCount" for method names.

Posted on: 2014/5/24 11:35
ChrisH
--
Author of the PortablE programming language.
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


Re: How detect transparent part of sprite
#5
Home away from home
Home away from home


See User information
OK, here is some code which SHOULD do what you want... BUT I HAVE NOT TESTED IT! Please let me know if it works or not (if not then I will have to test it myself & fix any bugs).

Quote:
<pre>
MODULE 'std/cGfxSimple'

PROC main()
DEF bitmap:PTR TO cGfxBitmap
DEF solid:PTR TO solidBitmap

->how to create a 'solid' bitmap
bitmap := LoadPicture('example.png', '')
NEW solid.new(gfx, bitmap)

->now use "solid" where you would have used "bitmap", say when creating a sprite.
FINALLY
PrintException()
ENDPROC


CLASS solidBitmap OF cGfxDrawable
bitmap:PTR TO cGfxBitmap
ENDCLASS

PROC new(win:PTR TO cGfxWindow, bitmap:PTR TO cGfxBitmap) OF solidBitmap
self.addToGfx(win)
self.bitmap := bitmap
ENDPROC

PROC infoWidth() OF solidBitmap RETURNS width IS self.bitmap.infoWidth()

PROC infoHeight() OF solidBitmap RETURNS width IS self.bitmap.infoHeight()

PROC draw(x, y) OF solidBitmap IS self.bitmap.draw(x, y)

PROC infoIsTransparent() OF solidBitmap RETURNS isTransparent:BOOL IS self.bitmap.infoIsTransparent()

->PROC hitCheck(insideX, insideY) OF solidBitmap RETURNS hit:BOOL IS TRUE ->this is the default behaviour of a cGfxDrawable, so we don't actually need this code

->PROC overlaps() ->we can use the default behaviour for this too (and it would be more complex to write, so I haven't bothered)

PROC changeUsageCount(increaseBy) OF solidBitmap
self.bitmap.changeUsageCount(increaseBy)
SUPER self.changeUsageCount(increaseBy)
ENDPROC

PROC registerForChanges(client:PTR TO cGfxNotifyOfDrawableChanges) OF solidBitmap
self.bitmap.registerForChanges(client)
SUPER self.registerForChanges(client)
ENDPROC

PROC unregisterForChanges(client:PTR TO cGfxNotifyOfDrawableChanges) OF solidBitmap
self.bitmap.unregisterForChanges(client)
SUPER self.unregisterForChanges(client)
ENDPROC
</pre>

Posted on: 2013/12/24 9:42
ChrisH
--
Author of the PortablE programming language.
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


Re: How detect transparent part of sprite
#4
Home away from home
Home away from home


See User information
I never thought anyone would want to do that, so I didn't add that option (and I don't think it is a common enough need to justify adding it).

But it MAY be possible to 'trick' PortablE's sprite system into thinking it is not transparent, by creating & using a cGfxDrawable subclass which is really just a cGfxBitmap:
http://cshandley.co.uk/portable/StandardFunctionality.html#20_7

I'll try to see if I can do it.

Posted on: 2013/12/24 9:19
ChrisH
--
Author of the PortablE programming language.
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


Re: How detect transparent part of sprite
#3
Just can't stay away
Just can't stay away


See User information
I also think that only hope is tracking sprite position and compare it with mouse coordinate, but is not as easy as click on it.

Posted on: 2013/12/24 5:43
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


Re: How detect transparent part of sprite
#2
Quite a regular
Quite a regular


See User information
For this you can just check if the mouse clicked in the rectangular bounds of the sprite.
You will have to loop through each sprite to find the one
that is closest to the mouse click.
This will be easy if the sprites are the same size.

Posted on: 2013/12/24 2:21
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 


How detect transparent part of sprite
#1
Just can't stay away
Just can't stay away


See User information
I start my new game. My sprites has some transparent area. I need draw that sprites with transparency, but I must detect clicks on all sprite area, even if user click on transparent part. So how draw sprites as transparent but detect all sprite area?

My typical code is simple:
CASE EVENT_MOUSE_LEFT, EVENT_MOUSE_DOUBLECLICK
IF FindSpriteAt(value,value2)<>NIL THEN i := LastSprite().getData()
-> action code for detected sprite
ENDIF

Posted on: 2013/12/23 16:11
 Top  Twitter  Facebook  Google Plus  Linkedin  Del.icio.us  Digg  Reddit  Mr. Wong 







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
4462
2 nikolaos
nikolaos
4206
3 magorium
magorium
4095
4 phoenixkonsole
phoenixkonsole
3942
5 deadwood
deadwood
2917
6 ncafferkey
ncafferkey
2810
7 mazze
mazze
2222
8 Kalamatee
Kalamatee
2212
9 clusteruk
clusteruk
2114
Powered by XOOPS © 2001-2025 The XOOPS Project