News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

CPCTELERA and RGAS

Started by Robert_Lee, 03:16, 28 October 17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Robert_Lee



Hi!

I'm trying this great tool for CPC after seeing the tutorial on the Juanje channel of Youtube (with the sprite of Willy).



The doubt I have is the following in RGAS:






When I export the sprite with the option CPCTelera / SDCC C arrays create me a .asm file.


Can be used directly or to pass to .c with cpct_rgas2c?

I have tried it with the latter and there is no way.

Thanks




Arnaud

Hello,
the sprite generated can be directy drawn by cpctelera.
You can copy this array in a c file and draw it with the function cpct_drawSprite.

The tool cpct_rgas2c is used to convert a sprite with asm format into c array format :


._NewSprite1
defb $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
defb $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00


to

const unsigned char G_NewSprite1[576] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,


The easier way to create a sprite is to include the file image you want to convert into the file
cfg\image_conversion.mk

CPCTelera will do all the job for you, after just have to include in your C file the header of the sprite generated.

You can take a look for this example under cpctelera directory :
examples\medium\blendedSprites




Robert_Lee

Hello Arnaud


I just discovered this page:


https://www.piskelap



[/size]I'll create the sprite looking for both sides and export it to png


I'll tell you how it goes :)


Thanks!


By the way, I think it is somewhat more explained in this video:





https://www.youtube.com/watch?v=zov-yI7I00s



I followed the example with the file that is to download and I have achieved it.


we will see if it works with mine.


SRS


Robert_Lee

Yes


I wonder if it is possible to create sprites with piskelap.


When I export the file to .png, I convert it with Paint to GIF
After, I convert it to CPC with convimgCPC.




But at the moment I have not seen it work for CPCTelera.










Arnaud

#5
Yes you can with CPCTelera :

- Export to PNG file your sprite on 1 line

- In image_conversion.mk you can specify the size of the individual sprite (it's explain file header)

ex:
$(eval $(call IMG2SPRITES,src/sprites/shoot.png,0,g,8,8,$(PALETTE),,src/gen_src))

Here the size of the sprites will be 8x8.

If i have set to 0x0 CPCTelera use the file to generate 1 sprite.


You can also add the option tileset, to generate a array with pointers to all sprites

ex:
$(eval $(call IMG2SPRITES,src/sprites/shoot.png,0,g,8,8,$(PALETTE),tileset,src/gen_src))


Robert_Lee

Arnaud, I do exactly that.






I wonder if the piskel graphics should be converted with ConvImgCPC, or you can directly add the PNG to the folder assets of CPCTelera.


Thus avoiding the process of having to use the Paint and ConvImgCPC.




The sprite picture :







The color format of the sprite to be in RGB or HEX?





Thanks!




Arnaud

#7
Quote from: Robert_Lee on 12:33, 01 November 17
I wonder if the piskel graphics should be converted with ConvImgCPC, or you can directly add the PNG to the folder assets of CPCTelera.
Thus avoiding the process of having to use the Paint and ConvImgCPC.

You can directly use your png with cpctelera, it will generate the .c and .h files automatically

Quote from: Robert_Lee on 12:33, 01 November 17
The color format of the sprite to be in RGB or HEX?

I think it doesn't matter but in doubt use RGB


If you need an example to draw your sprite with a cpctelera project, publish your png here i'll create it.

ronaldo

Hi @Robert_Lee,

   As @Arnaud says, CPCtelera autoconverts image files (PNG, BMP, GIF, JPG, etc) into sprite arrays in C directly. You just have to put them inside a folder in your project and add a line to cfg/image_conversion.mk file with the conversion parameters. Since then on, each time you write down "make" your file will be autoconverted before compiling your project. Moreover, as it is included as a Makefile macro, the autoconversion process only happens when required: if your original image file is not modified, conversion is only done once. Whenever you change your original image file, conversion is triggered again and you always have your graphics updated in your code, without repeating any manual conversion process. That's the reason why CPCtelera is designed this way: to save you time from the most bureaoucratic tasks in game development.

   In fact, the video you mentioned explains exactly how to copy an image to your project and add the conversion line. If you follow the steps in that video, you can use whatever image editor (pyxel, gimp, photoshop, aseprite...) and let CPCtelera autoconvert your PNGs to CPC arrays without doing anything else.

   If something is not clear enough and you need help with some part, we are here to help :).

Good luck with your projects!

Robert_Lee

#9
Hi Arnaud, Ronaldo  :)






The example of the video I do it as it is said and it works correctly with the file that I download from youtube.




The problem comes when the sprite is created by me.


The sprite:


https://www.dropbox.com/s/gq1q6urugbafacq/nene.png?dl=0


The  .h file:


// Data created with Img2CPC - (c) Retroworks - 2007-2015
#ifndef _ASSETS_NENE_H_
#define _ASSETS_NENE_H_


#include <types.h>
extern const u8 g_palette[16];


#define G_NENE_0_W 8
#define G_NENE_0_H 27
extern const u8 g_nene_0[8 * 27];
#define G_NENE_1_W 8
#define G_NENE_1_H 27
extern const u8 g_nene_1[8 * 27];


#endif





the .c file:


onst u8 g_palette[16] = { 0x54, 0x44, 0x5c, 0x58, 0x45, 0x56, 0x46, 0x5e, 0x40, 0x47, 0x42, 0x53, 0x5a, 0x4a, 0x43, 0x4b };


// Tile g_nene_0: 16x27 pixels, 8x27 bytes.
const u8 g_nene_0[8 * 27] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x0c, 0x0c, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x08, 0x04, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x08, 0x0c, 0x08, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x08, 0x08, 0x08, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x08, 0x08, 0x0c, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x08, 0x00,
   0x00, 0x00, 0x00, 0x04, 0x08, 0x0c, 0x04, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x08, 0x04, 0x04, 0x08,
   0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x04, 0x08,
   0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x0c, 0x08,
   0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x0c, 0x08,
   0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x04, 0x0c, 0x08, 0x00, 0x00,
   0x00, 0x04, 0x0c, 0x0c, 0x0c, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x0c, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};


// Tile g_nene_1: 16x27 pixels, 8x27 bytes.
const u8 g_nene_1[8 * 27] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0c, 0x0c, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x08, 0x04, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x04, 0x0c, 0x04, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x04, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x00,
   0x00, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x04, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x04, 0x04, 0x04, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x08, 0x0c, 0x04, 0x08, 0x00, 0x00, 0x00,
   0x04, 0x08, 0x08, 0x04, 0x0c, 0x00, 0x00, 0x00,
   0x04, 0x08, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00,
   0x04, 0x0c, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00,
   0x04, 0x0c, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x0c, 0x08, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x04, 0x0c, 0x0c, 0x0c, 0x08, 0x00,
   0x00, 0x00, 0x04, 0x0c, 0x0c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};





The error:





Thanks!











ronaldo

Quote from: Robert_Lee on 12:21, 02 November 17
The error:




The error says "main.c:41: syntax error: token -> "."  ; column 10". So, the error seems to be in your code, in main.c file. In fact, converted files from your sprite seem to have already been compiled, because make starts by compiling main.c. Therefore, it seems to be no problem at all with your sprite, but something regarding line 41 of your main.c file.

Robert_Lee

#11
Thanks, Ronaldo, already solved! :D



Thanks!

Robert_Lee

#12
Well, now it keeps restart the emulator every time i execute it :(


in principle the code is ok.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

//-----------------------------LICENSE NOTICE------------------------------------
//  This file is part of CPCtelera: An Amstrad CPC Game Engine
//  Copyright (C) 2015 ronaldo / Fremos / Cheesetea / ByteRealms (@FranGallegoBR)
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

#include <cpctelera.h>
#include "fantasma.h"
#include "map1.h"
#include "tiles.h"
#include "retropolis.h"

#define SI 1
#define NO 0
#define  ORIGEN_MAPA_Y 68
#define  ORIGEN_MAPA cpctm_screenPtr(CPCT_VMEM_START, 0,ORIGEN_MAPA_Y)

typedef struct {
    u8 x, y;
    u8* sprite;
    u8  mover;
} TProta;

TProta prota;
u8* mapa;

cpctm_createTransparentMaskTable(g_tablatrans, 0x0100, M0, 0);

void dibujarMapa() {
    cpct_etm_drawTilemap2x4 (g_map1_W, g_map1_H, ORIGEN_MAPA, mapa);
}

void dibujarRotulo() {
    cpct_drawSprite (g_retropolis_0,
                     cpctm_screenPtr(CPCT_VMEM_START, 0, 0)
                     ,G_RETROPOLIS_0_W, G_RETROPOLIS_0_H);
    cpct_drawSprite (g_retropolis_1,
                     cpctm_screenPtr(CPCT_VMEM_START, G_RETROPOLIS_0_W, 0)
                     ,G_RETROPOLIS_1_W, G_RETROPOLIS_1_H);
}

void dibujarProta() {
    u8* pvmem = cpct_getScreenPtr(CPCT_VMEM_START, prota.x, prota.y);
    cpct_drawSpriteMaskedAlignedTable (prota.sprite, pvmem, G_FANTASMA_0_W, G_FANTASMA_0_H, g_tablatrans);
}

void moverIzquierda() {
    if (prota.x > 0) {
        prota.x--;
        prota.mover  = SI;
     }
}

#define ANCHO_PANTALLA 80
#define LIMITE_DERECHO ANCHO_PANTALLA - G_FANTASMA_0_W

void moverDerecha() {
     if (prota.x < LIMITE_DERECHO) {
         prota.x++;
         prota.mover  = SI;
     }
}

void comprobarTeclado(){
    cpct_scanKeyboard_if();

    if (cpct_isAnyKeyPressed()) {
        if (cpct_isKeyPressed(Key_CursorLeft))
            moverIzquierda();
        else if (cpct_isKeyPressed(Key_CursorRight))
            moverDerecha();
    }
}

void inicializar() {
  cpct_disableFirmware();
  cpct_setVideoMode(0);
  cpct_setBorder(HW_BLACK);
  cpct_setPalette(g_palette, 16);

  mapa = g_map1;
  cpct_etm_setTileset2x4(g_tileset);
  dibujarMapa();

  dibujarRotulo();


  prota.x  = 20;
  prota.y  = 157;
  prota.mover = NO;
  prota.sprite = g_fantasma_0;
  dibujarProta();
}

void main(void) {
    inicializar();
    while (1) {
        comprobarTeclado();
        if (prota.mover) {
        dibujarProta();
        prota.mover = NO;
    }
  }
}




I do not understand why the emulator does not stop reset when I execute it.

Robert_Lee




Here is the file with the proof that I am doing:




https://www.dropbox.com/s/dwc69vwo50x8knc/juego.rar?dl=0


I do not understand why it does not load.


Thanks

Arnaud

#14
Hello,

replace the following line :

cpctm_createTransparentMaskTable (g_tablatrans, 0x0100, M0, 0);

with

cpctm_createTransparentMaskTable (g_tablatrans, 0x8000, M0, 0);


It doesn't work because in the file juego.map you can see the address 0x100 is already used by a global variable g_tablatrans_0

      Value  Global                              Global Defined In Module
      -----  --------------------------------   ------------------------
     00000000  .__.ABS.                           cpct_sprites
     00000000  l__CABS                         
...                   
     00000100  l__g_tablatrans_0


But i don't know what is this variable and why she is at this location (the variable is always here even when i set g_tablatrans to 0x8000).

I think @ronaldo can explains this.

Robert_Lee

Thanks, Arnaud




Those numbers are the memory addresses?




By the way, I always get an error message of "g_palette" when i compile.


I have to compile twice to launch the demo because at the first I get that error message.




Another question I have is:


there is no tutorial to make the sprite look both ways

and to expand the map?


Thanks!


Arnaud

Hello,

Quote from: Robert_Lee on 13:55, 08 November 17
Those numbers are the memory addresses?
Yes

Quote from: Robert_Lee on 13:55, 08 November 17
By the way, I always get an error message of "g_palette" when i compile.
I haven't got the error with your code.
Try to enter:
make clean all


Quote from: Robert_Lee on 13:55, 08 November 17
there is no tutorial to make the sprite look both ways
Here is an example under cpctelera to flip the sprite :
cpctelera-1.4.2\examples\medium\flipSprites

Quote from: Robert_Lee on 13:55, 08 November 17
and expand the map
What you mean exactly by "expand the map" ?

Arnaud.

Powered by SMFPacks Menu Editor Mod