Welcome, Guest. Please login or register.
June 19, 2013, 06:19:37 am

Login with username, password and session length
Members
Total Members: 488
Latest: Wimmie
Stats
Total Posts: 7309
Total Topics: 1178
Online Today: 5
Online Ever: 229
(April 05, 2011, 09:10:50 am)
Users Online
Users: 0
Guests: 6
Total: 6
Permissions

A Squeakyduck Design product
Pages: [1]
Print
Author Topic: Sprite collision with non-sprite  (Read 792 times)
Squiffy
Cobra Owner
Newbie
*
Offline Offline

Posts: 35



« on: December 31, 2006, 02:23:53 am »

Is it possible to tell if a sprite has collided with a previously drawn shape (say a rectangle drawn with rect) ?
I know I could keep a list of all the rects at x/y and their w & h's and check for coordinates every loop, just wondered if I could put a collision field around a shape to avoid this.

Reason I don't just use a sprite for this is because I am drawing a rectangle that increases in size every 50ms until it hits a maximum. While it is increasing in size, it is vunerable to being hit by baddies. As far as I can see I can't scale a 2d sprite, so I am using a filled rect and a loop for the drawing.

Once it's fully drawn, it becomes an obstacle for the baddies rather than a vunerability for the player. In this state, I could just replace the rect with a sprite of the final size (it's a known final size). It's the growing stage I need to check for collisions.

Squiffs.
Logged

I can, I just don't want to.
Fluke
Moderator
Jr. Member
*****
Offline Offline

Posts: 349



« Reply #1 on: December 31, 2006, 07:53:26 am »

Quote
As far as I can see I can't scale a 2d sprite

It's actually very easy to scale a sprite Smiley
Code:
SpriteWidth(yourSprite, size)
SpriteHeight(yourSprite, size)

Don't know how/if collision works with a scaled sprite - if it does, then cool - if not, it shouldn't be hard to manually check if you're just drawing a rectangle.
Logged
Squiffy
Cobra Owner
Newbie
*
Offline Offline

Posts: 35



« Reply #2 on: December 31, 2006, 08:10:11 am »

Hmm.. I tried the scaled sprite last night and it appeared only to draw as much of the sprite as width height allowed (clipping the rest instead of making it smaller).

However, tried it just now and it works fine, so god only knows what I was doing last night.

I genuinely think I'm going mad, this is the second time I've had the solution and been convinced it doesn't work.

I think it's about time I stopped coding at 2am....

Thanks, Fluke. I think I'll sleep on the next question before posting....

« Last Edit: December 31, 2006, 09:03:33 am by Squiffy » Logged

I can, I just don't want to.
GrahamK
Administrator
Hero Member
*****
Offline Offline

Posts: 2031


Cobrabytes
« Reply #3 on: December 31, 2006, 01:21:26 pm »


Yeah, collisions are only between sprites

but

collision should work on scaled/rotated sprites with no probs.

Logged
Squiffy
Cobra Owner
Newbie
*
Offline Offline

Posts: 35



« Reply #4 on: December 31, 2006, 01:52:59 pm »

All seems to be working fine now with scaled sprites.
I was having a durrr moment. They seem more frequent these days.....
Logged

I can, I just don't want to.
Pages: [1]
Print
Jump to: