Help for newbies

Post Reply
Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Help for newbies

Post by Tantrixx »

Dear friends, as much as possible using the command "get touch" to make the sprite move not smoothly, and with a step 23, for example? Thank you.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Help for newbies

Post by Operator »

Hello Tantrixx, please post your code to
see what is "not working".
As a general rule avoid any graphics command
while using Sprites to speed all up (run smoothly).

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Help for newbies

Post by Tantrixx »

Operator wrote:Hello Tantrixx, please post your code to
see what is "not working".
As a general rule avoid any graphics command
while using Sprites to speed all up (run smoothly).

Code: Select all

GET TOUCH 0 AS x10,y10
GET SPRITE "1ship10" POS xx10,yy10
IF x10>34.5 AND y10>68 AND x10<242.5 AND y10<208 AND SPRITE_HIT ("1ship10",x10,y10)=1 THEN
SPRITE "1ship10" AT x10,y10 ANGLE z
ENDIF


IF xx10>34.5 AND xx10<47.5 AND SPRITE_HIT ("1ship10",x10,y10)=0 THEN
x10=34.5 ! y10=yy10
SPRITE "1ship10" AT x10,y10 ANGLE z
ENDIF

IF xx10>45.5 AND xx10<70.5 AND SPRITE_HIT ("1ship10",x10,y10)=0 THEN
x10=57.5 ! y10=yy10
SPRITE "1ship10" AT x10,y10 ANGLE z
ENDIF
Oerator, this part of the code, which in contact with certain coordinates, sprite stands in its place. Coordinates "x" work, and the coordinates of "y" is not working. That is work that previously written. I have an area of ​​10x10 cells, it is necessary that when moving a sprite rose clearly in certain areas, or moved in increments of 23, for example. 23 is the size of the cell.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Help for newbies

Post by Operator »

I made a snippet trying to replicate your
issue... hope this helps...

Code: Select all

REM 
REM grid test with ball
REM 

GRAPHICS
GRAPHICS CLEAR 0,0,0

'grid color
DRAW COLOR 0,1,0

'ball color and ball radius r
FILL COLOR 1,0,0
r = 11.5

'grid (cell) size and offset
cell_width = 23
cell_x_max = 10
cell_y_max = 10
grid_xOff = 30
grid_yOff = 60

REFRESH OFF

LOOP:
GRAPHICS CLEAR 0,0,0
DRAW TEXT "Touch inside the grid" AT 0,0

'paint the grid 10x10 cells
FOR xi= 0 TO cell_x_max 
  x1 = grid_xOff + xi*(cell_width+2)
  y1 = grid_yOff 
  x2 = x1
  y2 = grid_yOff + cell_y_max*(cell_width+2)
  DRAW LINE x1,y1 TO x2,y2
NEXT xi

FOR yi = 0 TO cell_y_max
  x1 = grid_xOff
  y1 = grid_yOff + yi*(cell_width+2)
  x2 = grid_xOff + cell_x_max*(cell_width+2)
  y2 = y1
  DRAW LINE x1,y1 TO x2,y2 
NEXT yi

GET TOUCH 0 AS tx,ty
IF tx> 0 THEN
  tx_old = tx
  ty_old = ty
END IF

'paint the ball clamped to the grid 
'int(tx_old/cell_with) allows only grid size
'steps -> "not smooth" for c_xi
c_xi = -7.5 + (cell_width+2)*INT(tx_old/cell_width)
c_yi = -2.5 + (cell_width+2)*INT(ty_old/cell_width)

'bounds of the grid
IF c_xi >= grid_xOff AND c_xi <= (grid_xOff+ (cell_width + 2)*cell_x_max) THEN
  IF c_yi >= grid_yOff AND c_yi <= (grid_yOff+ (cell_width + 2)*cell_y_max) THEN
FILL CIRCLE c_xi,c_yi SIZE r
  END IF
END IF

REFRESH
GOTO LOOP


Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Help for newbies

Post by Tantrixx »

Operator, you are a great programmer :). Without you I would not be able to cope. But I think in the right direction, and probably a very long time without thinking you :). At the moment I do not have to complete the happiness of another. I need sprite is rotated 90 degrees for example, when you double-click on the sprite.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Help for newbies

Post by Operator »

I whish I was one :)
Check the double tap to rotate a sprite
snipped...

Code: Select all

REM 
REM double tap/hit on sprite test
REM 

GRAPHICS
GRAPHICS CLEAR
REFRESH OFF
scr_w2 = SCREEN_WIDTH()/2
scr_h2 = SCREEN_HEIGHT()/2
OPTION SPRITE POS CENTRAL
OPTION ANGLE DEGREES

'make a sprite
FILL COLOR 1,0,0
DRAW COLOR 1,1,1
FILL CIRCLE 50,50 SIZE 25
DRAW ARC 50,50, 25, 0,90
SPRITE "circ1" SCAN 50-27,50-27, 54,54

'make a second sprite
FILL COLOR 0,1,0
FILL CIRCLE 50,50 SIZE 25
SPRITE "circ2" SCAN 50-27,50-27, 54,54

SPRITE "circ2" AT scr_w2,scr_h2 SCALE 2
SPRITE "circ1" AT scr_w2,scr_h2 SCALE 5
SPRITE "circ2" SHOW
SPRITE "circ1" SHOW

FIELD "info" TEXT " " AT 0,0 SIZE 320,50 ML RO 
FIELD "info" BACK COLOR 0,0,0
FIELD "info" FONT COLOR 1,1,1
FIELD "info" TEXT "Double Tap the green circle in < 0.5sec."

GRAPHICS CLEAR 0,0,0

LOOP:

GET TOUCH 0 AS tx,ty
IF SPRITE_HIT ("circ2", tx,ty) THEN
  was_touched = 1
END IF

GET TOUCH 0 AS tx,ty
IF SPRITE_HIT ("circ2", tx,ty) = 0 AND was_touched = 1 THEN
  T1 = TIME()
  was_touched = 0
END IF

GET TOUCH 0 AS tx,ty
IF SPRITE_HIT ("circ2", tx,ty) THEN
  dt = TIME()-T1
  FIELD "info" TEXT "Double Tap the grenn circle in < 0.5sec."&" Time since last Tap: "&dT&" sec."
  IF dt > 0 AND dT < 0.5 THEN      
     ang = ang+90
     SPRITE "circ1" AT scr_w2,scr_h2 SCALE 5 ANGLE ang
     PAUSE 0.15
  END IF
END IF
  
GOTO LOOP


Post Reply