Author Topic: Simple polysprite command with smart draw  (Read 2045 times)

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
I've replaced the use of drawsprite with a simple command that creates a polyvector instead, due to improved performance and greater flexibility that polyvector provides.  Also since I'm using large graphics and there is clipping, I updated the command to be a little smarter, only drawing in the screen and what is visible.

screen_width and screen_height need to be defined by you though.  Doesn't have scaling or rotation features yet, but I need to do them soon for my project.


Code: GLBasic [Select]
  FUNCTION DrawPolySprite: image, x, y, w, h, color
    LOCAL adjx = x, adjy = y, adjw = w, adjh = h, adjsw = 0, adjsh = 0, adjpw = w, adjph = h
    //Optimize
    IF x < 0
      adjx = 0
      adjsw = -x
      adjpw = w+x
    ELSEIF x+w > screen_width
      adjw = w+screen_width-x
      adjpw = adjw
    ENDIF
    IF y < 0
      adjy = 0
      adjsh = -y
      adjph = h+y
    ELSEIF y+h > screen_height
      adjh = h+screen_width-y
      adjph = adjh
    ENDIF
    //Create
    STARTPOLY image, 0
      POLYVECTOR adjx, adjy, adjsw, adjsh, color
      POLYVECTOR adjx, adjy+adjph, adjsw, adjh, color
      POLYVECTOR adjx+adjpw, adjy+adjph, adjw, adjh, color
      POLYVECTOR adjx+adjpw, adjy, adjw, adjsh, color
    ENDPOLY
  ENDFUNCTION
 
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Simple polysprite command with smart draw
« Reply #1 on: 2010-May-14 »
Um, I'm being lazy and should really spend 10 mins writing a routine to test this, but is polyvector faster than drawsprite? Surely not.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1540
    • View Profile
Re: Simple polysprite command with smart draw
« Reply #2 on: 2010-May-14 »
With tests, I also wonder the efficiency of this, especially on the iPhone. To find if the DRAWSPRITE function, that is partially drawn on the screen, faster than the spliced DrawPolySprite function calculations.  :blink:
« Last Edit: 2010-May-14 by matchy »

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: Simple polysprite command with smart draw
« Reply #3 on: 2010-May-14 »
I haven't tested it much either, but it does provide some features over drawsprite like coloring vectors and scaling/tiling.

Also if you're using the same image, you can extract the start poly and endpoly, which I have done with another command called 'setpolysprite'

startpoly img, 2
  newpolystrip
  setpolysprite
endpoly

Something like that, good for handling lots of the same image.  You can mess around with it further to support tilesheets, but I haven't done that myself.  In theory though, you can have large chunks of your graphics on spritesheets and really take advantage of polysprite that way.

I use this mostly to handle the larger images that make of the map for my horizontal shooting game.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/