GLBasic forum

Main forum => GLBasic - en => Topic started by: Jonás Perusquía on 2013-Jul-01

Title: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Jonás Perusquía on 2013-Jul-01
Hello there all community members :)

I recently tried some scaling code using ZOOMSPRITE and ROTOZOOMSPRITE, however, the SPRCOLL didn't like those commands because it detects the current size of the original loaded sprite, and not the printed zoomed sprite.
i was thinking on a solution... using GRABSPRITE but i'm not sure if it will work because of my game having a background...

Thanks in advance :)!
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: mentalthink on 2013-Jul-01
I never try to do this, but if you try to search some pixel don't it's black, but looking only in a layer... something whit getpixel, but only it's looking what happend in the rectangle of your sprite, to getpixel doen't matter backgrounds or another sprites in the same time on screen...
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Ian Price on 2013-Jul-01
I overcame this in my Balloonacy game.

Create a virtual screen and do the rotozoomsprite onto it, then display that virtual screen sprite in the game and collision works perfectly. :)
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Jonás Perusquía on 2013-Jul-04
sorry for the delay, i will try that trick and come here again as soon as possible :D
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: erico on 2013-Jul-04
Never a trick!... Technic!  ;) :P :D (that is a joke from the past, don´t worry :))

I hope it works out! :good:
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Jonás Perusquía on 2013-Jul-05
tecnhique haha :D can you please provide me some pseudo-code please? :X
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Ian Price on 2013-Jul-05
Here's a fully working piece of code. You'll have to replace the blocks with your image and make sure that the second virtual screen is large enough to display the image fully rotating (otherwise you could cut bits of the image off).

Code (glbasic) Select

// Project: roto sprite collision
// Start: Friday, July 05, 2013
// IDE Version: 10.283


// SETCURRENTDIR("Media") // go to media files

SETSCREEN 640,480,0

GLOBAL angle#

GLOBAL mx%, my%, b1%, b2%

SYSTEMPOINTER TRUE


// Create an odd shaped sprite out of rects
CREATESCREEN 1,1,128,128
USESCREEN 1
DRAWRECT 32,32,64,64,RGB(255,0,0)
DRAWRECT 64,64,64,64,RGB(255,0,0)

// Create actual virtual screen that we will rotate sprite onto
CREATESCREEN 2,999,180,180

// Create mouse pointer sprite
CREATESCREEN 3,5,2,2
USESCREEN 3
DRAWRECT 0,0,2,2,RGB(255,0,255)

// Use the normal screen for all other operations
USESCREEN -1

// Repeat until ESC pressed
WHILE TRUE

// Get mouse position and use this for collision detection
MOUSESTATE mx,my,b1,b2

// Usse virtual screen 2 for drawing operations
USESCREEN 2
  DRAWRECT 0,0,180,180,RGB(255,0,128) // Clear screen

  // Draw rotated sprite onto screen 2
  ROTOSPRITE 1,26,26,angle#
 
  // Increase rotation
  INC angle#,0.5

// Revert back to normal drawing screen
USESCREEN -1

// Draw the virtual screen onto normal screen as a sprite
DRAWSPRITE 999,200,150

// If mouse collides with rotaing image then let user know
IF SPRCOLL(5,mx,my, 999,200,150) THEN PRINT "COLLISION!!!!!",10,10

SHOWSCREEN

WEND


Move the mouse around the screen and test for collisions on the rotating sprite.
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Jonás Perusquía on 2013-Jul-06
does it also works with ROTOZOOMSPRITE? i have some code that makes the image bigger depending on screensize Y

THANKS FOR SHARING your code! :)

Code (glbasic) Select

IF PLATFORMINFO$("") = "ANDROID" OR PLATFORMINFO$("") =  "IPHONE" // CHECK FOR MOBILE RESOLUTIONS
    SETORIENTATION 1
    scale_x2=1.6 // IF YES, SCALE THE IMAGES AND SET ORIENTATION PORTRAIT
ELSE
    scale_x2=1  //IF NOT, LEAVE IMAGES AS THEY ARE
ENDIF

LOCAL life_Scale = ((sy/100)/(yy3*.19)) * scale_x2
IF hp>3
    hp=3
ELSEIF hp=3
    FOR pos=56 TO 68 STEP 6
        ZOOMSPRITE 3, (sx/100*pos), sy/100*life_Scale, life_Scale, life_Scale
    NEXT
ELSEIF hp>=2 AND hp<3
    FOR pos=56 TO 62 STEP 6
        ZOOMSPRITE 3, (sx/100*pos), sy/100*life_Scale, life_Scale, life_Scale
    NEXT
ELSEIF hp>=1 AND hp<2
    ZOOMSPRITE 3, (sx/100*56), sy/100*life_Scale, life_Scale, life_Scale
ELSEIF hp<1
    GOSUB GAMEOVER
ENDIF


this is a sample that i use for Android
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: kanonet on 2013-Jul-06
Of cause it does as long as you remember to make the offscreen big enough.
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Jonás Perusquía on 2013-Jul-06
 :O still trying to understand your code Ian Price :S
haha

by the way, what about GRABSPRITE?
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: Ian Price on 2013-Jul-06
You can use GRABSPRITE to create the sprite (or POLYVECTOR or DRAWLINE or ...), but I thought you'd want to actually load in your own image.

My code above was created so that you could get an understanding of virtual screens - how to create them, how to draw to them and how to use them in real world applications.

And yes, you can use ROTOZOOMSPRITE - just ensure that the screen you are drawing the zoomed/rotated sprite to is large enough to incorporate the full image without clipping, as kanonet said.
Title: Re: Help with SPRCOLL and ROTOZOOMSPRITE
Post by: spacefractal on 2013-Jul-06
normally im dont like virutal screen, because they have some issues (multiple, slowdown etc), but this trick is very very nice used for rotated based collisions.