News:

Function Finder  Find all the functions within source code files

Main Menu

Question on Sprite Images

Started by Tracy, January 16, 2006, 09:33:10 PM

Previous topic - Next topic

Tracy

Hi there.  I had a quick question in regards to animating a sprite. In my case, I want to make a projectile that rotates around as though it were a 2D rolling ball.

The problem I'm running into is that my image is square. I can get it to show up as a circle using ImageMaskColour, but not if I use PrepareFXIMage as well. I've tried executing the command in all sorts of different places in my coding sequence, and it gives me my corners back no matter what I seem to do.

Is there a way to have PrepareFXImage and ImageMaskColour active at the same time so I can get the rotating ball effect on my fireball I'm after? If not, is there another way to do it that I'm missing?

Thanks for your time. I'm having fun playing around with your program, and so far this is the only thing that's stumped me that I haven't been able to figure out with the Help indices.

kevin

#1
Howdy, 

   You'll have to post a (cut down) example of what you have, so we can get a clearer picture of  how your doing things.

kevin

#2
try this


PlayBASIC Code: [Select]
   sw=getscreenwidth()
sh=getscreenHeight()


;======================
; Make Ball Image
; ======================
BallIMage=NewBallImage(64,rgb(255,255,255))
Preparefximage BallIMage


;======================
; Render with sprite
;======================
MySprite=NewSprite(sw/2,sh/2,BallImage)
SpriteDRawmode MySprite,2
centerspritehandle MySprite


Do
Cls 255
; render as rotated images
DrawRotatedimage BallImage,200,100,angle#,1,1,-32,-32,false
DrawRotatedimage BallImage,400,100,angle#,1,1,-32,-32,true

RotateSprite MySprite,Angle#

angle#=wrapangle(angle#,1)

drawallsprites
Sync
loop

;*=-------------------------------------------------------------=*
; New Ball IMage
;*=-------------------------------------------------------------=*
; Creates a coloured ball (looking image)

Function NewBallImage(size,col)
OldSurface=getSurface()
ThisImage=Newimage(Size,Size)
rendertoimage ThisImage
MaskCOlour=rgb(255,0,255) ; sill with purple (which will be mask colour)
Cls MaskCOlour
RenderPhongImage ThisImage,Size/2,Size/2,col,255,260/(size/2)
CenterText size/2,size/2,"Ball"
IMageMaskcolour Thismiage,MaskColour
rendertoImage OldSurface
EndFunction ThisIMage






Tracy

#3
Here's the function in question. I'm sure you'll recognize it as frankenstein code taken from your 2D scroller and Bathsteroids, but hey, this is the beginner's forum, right?

PlayBASIC Code: [Select]
Function CReate_Bullet(Bullet,xpos#,ypos#)            
Inc Bullet_Qty
Bullet(Bullet).Xpos# =xpos#
Bullet(Bullet).Ypos# =ypos#

If PLayer(1).facingleft=0 Then Bullet(Bullet).XSpeed# =7
If PLayer(1).facingleft=1 Then Bullet(Bullet).XSpeed# =-7
Bullet(Bullet).YSpeed# =0

Bullet(Bullet).XAccel# =0
Bullet(Bullet).YAccel# =Gravity#-0.2

b=GetFreeSprite()
CreateSprite b
Bulletimage=GetFreeImage()

LoadImage "Fireball.png",Bulletimage

ScaleImage Bulletimage,10,10,1
PrepareFXImage Bulletimage
ImageMaskColour Bulletimage,RGB(0,255,0)

SpriteImage b,Bulletimage

SpriteCollision b,True
SpriteCollisionClass b,1
SpriteCollisionMode b,0
PositionSprite b,xpos#+18,ypos#+13

Bullet(Bullet).Spr =b

EndFunction




Like I said, I've tried several different command orders and no luck. Thanks for the quick reply.

*Note* I'm 'green-screening' my graphics in this case instead of using the black background that's automatically set as the ImageMaskColour. I've tried it with a black background too, though, to no avail.

Tracy

Thanks. I'll try to learn what I can from that code.

kevin

Hmm, It's most likely the Image still has alpha channel on it.  But my guess is the image. Can you post it ?

Tracy

#6
QuoteHmm, It's most likely the Image still has alpha channel on it.  But my guess is the image. Can you post it ?

Well, I have no idea how to post it. At least, not directly. Here it is in attachment form, though.

And I haven't looked into Alpha channels. In fact, I have no idea what they are, even. (But I'm about to read up on it. Thanks for the possible tip.)

Edit: Apparently I DO know how to post it. Who knew?

kevin

#7
So that was the problem image ?.  It seems to work with the following snippet.  

 Note: The Image mask seems to be black rather than green.. ie  rgb(0,0,0)    



PlayBASIC Code: [Select]
   sw=getscreenwidth()
sh=getscreenHeight()


;======================
; Make Ball Image
; ======================
Ballimage=loadnewimage("pic.png")
scaleimage Ballimage,100,100,2
Preparefximage BallIMage


;======================
; Render with sprite
;======================
MySprite=NewSprite(sw/2,sh/2,BallImage)
SpriteDRawmode MySprite,2
centerspritehandle MySprite


Do
Cls 255
; render as rotated images
DrawRotatedimage BallImage,200,100,angle#,1,1,-32,-32,false
DrawRotatedimage BallImage,400,100,angle#,1,1,-32,-32,true

RotateSprite MySprite,Angle#

angle#=wrapangle(angle#,1)

drawallsprites
Sync
loop





Tracy

#8
Kevin, you're a saint.

This looks like it's going to be much easier than what I was trying to do anyway. I'll try to frankenstein this stuff into my game and see if I can get it to work.

Now for a more convoluted question: can you tell off the top of your head why my version of the code doesn't work properly? I'll take 'no' for an answer, go on my merry way, and count my blessings that you've already helped me out if you'd rather not bother.

If I'm doing something improperly (nevermind inefficiently), though, I'd rather know what.

I'll fiddle with it for a few more minutes before I go to bed, though I'm admittedly far from the top of my game right now. I'll let you know if I can get it to work properly. Thanks again.

Edit: And yes, that's the black background version. I'll just use that one since it seemed to work for you. I double checked the RGB value of the background of the other one and it matched, though, so I don't think that's the problem.

kevin

After a very quick look,  It doesn't appear that you set the sprites DrawMode to rotated.  

Ie

CreateSprite b
SpriteDRawMode b, 2  ;   2 = rotated  


Check the help for the modes, there's lots of them.  Some require you set other vallue in order to take effect though.

Tracy

#10
Got it. Thanks again for your help.

I'm quite certain I'll be back. I'm having too much fun with this already.

Edit: I got it to work your way, not mine. The rotation wasn't so much the problem as was the fact that I kept getting my corners back. (I hadn't gotten to trying to rotate it yet.) Thanks much for the help. I haven't decided yet if I'm going to keep with this past the trial period, but having such accessable online support will definitley aid in my decision. Best wishes to you.

kevin

Glad it's working. One way or another.  

Also, The current trial (PB1.089c)  lasts about 2 months ( to fit in with our game first game making competition).  So there's no rush about these things.    Tinker away :)

Tracy

QuoteGlad it's working. One way or another. 

Also, The current trial (PB1.089c)  lasts about 2 months ( to fit in with our game first game making competition).  So there's no rush about these things.    Tinker away :)

I'll do just that. Next issue: Figuring out why every so often a fireball sprite appears and doesn't move or clear. Ah... the joys of debugging.

Thanks again.